cache

package
v0.0.1-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemcachedCache

type MemcachedCache[T any] struct {
	// contains filtered or unexported fields
}

MemcachedCache are distributed cache that stores values in Memcaches caching service.

The current implementation does not support authentication.

Configuration parameters:

  • connection(s):
  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • host: host name or IP address
  • port: port number
  • uri: resource URI or connection string with all parameters in it
  • options:
  • max_size: maximum number of values stored in this cache (default: 1000)
  • max_key_size: maximum key length (default: 250)
  • max_expiration: maximum expiration duration in milliseconds (default: 2592000)
  • max_value: maximum value length (default: 1048576)
  • pool_size: pool size (default: 5)
  • reconnect: reconnection timeout in milliseconds (default: 10 sec)
  • retries: number of retries (default: 3)
  • timeout: default caching timeout in milliseconds (default: 1 minute)
  • failures: number of failures before stop retrying (default: 5)
  • retry: retry timeout in milliseconds (default: 30 sec)
  • idle: idle timeout before disconnect in milliseconds (default: 5 sec)

References:

- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

Example:

	ctx := context.Background()

    cache := NewMemcachedCache[string]();
    cache.Configure(ctx, cconf.NewConfigParamsFromTuples(
      "host", "localhost",
      "port", 11211,
    ));

    err := cache.Open(ctx)
      ...

    ret, err := cache.Store(ctx, "key1", []byte("ABC"))
    if err != nil {
    	...
    }

    res, err := cache.Retrive(ctx,"key1")
    value, _ := res.([]byte)
    fmt.Println(string(value))     // Result: "ABC"

func NewMemcachedCache

func NewMemcachedCache[T any]() *MemcachedCache[T]

NewMemcachedCache method are creates a new instance of this cache.

func (*MemcachedCache[T]) Close

func (c *MemcachedCache[T]) Close(ctx context.Context) error

Close method are closes component and frees used resources. Parameters:

  • ctx context.Context transaction id to trace execution through call chain.

Retruns: error or nil no errors occured.

func (*MemcachedCache[T]) Configure

func (c *MemcachedCache[T]) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure method are configures component by passing configuration parameters.

  • ctx context.Context
  • config configuration parameters to be set.

func (*MemcachedCache[T]) Contains

func (c *MemcachedCache[T]) Contains(ctx context.Context, key string) bool

Contains check is value stores Parameters:

  • ctx context.Context transaction id to trace execution through call chain.
  • key a unique value key.

func (*MemcachedCache[T]) IsOpen

func (c *MemcachedCache[T]) IsOpen() bool

IsOpen Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*MemcachedCache[T]) Open

func (c *MemcachedCache[T]) Open(ctx context.Context) error

Open method are opens the component. Parameters:

  • ctx context.Context transaction id to trace execution through call chain.

Retruns: error or nil no errors occured.

func (*MemcachedCache[T]) Remove

func (c *MemcachedCache[T]) Remove(ctx context.Context, key string) error

Remove method are removes a value from the cache by its key. Parameters:

  • ctx context.Context transaction id to trace execution through call chain.
  • key a unique value key.

Retruns: an error or nil for success

func (*MemcachedCache[T]) Retrieve

func (c *MemcachedCache[T]) Retrieve(ctx context.Context, key string) (value T, err error)

Retrieve method are retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns nil. Parameters:

  • ctx context.Context transaction id to trace execution through call chain.
  • key a unique value key. Retruns: cached value or error.

func (*MemcachedCache[T]) SetReferences

func (c *MemcachedCache[T]) SetReferences(ctx context.Context, references cref.IReferences)

SetReferences are sets references to dependent components.

  • ctx context.Context
  • references references to locate the component dependencies.

func (*MemcachedCache[T]) Store

func (c *MemcachedCache[T]) Store(ctx context.Context, key string, value T, timeout int64) (result T, err error)

Store method are stores value in the cache with expiration time. Parameters:

  • ctx context.Context transaction id to trace execution through call chain.
  • key a unique value key.
  • value a value to store.
  • timeout expiration timeout in milliseconds.

Returns: error or nil for success

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL