cache

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Returns the value for the given key.
	// If the key is not found, it returns nil and false.
	Get(ctx context.Context, key string) (any, bool)
	// Sets the value for the given key.
	// If the key already exists, it returns an error.
	Set(ctx context.Context, key string, value any) error
	// Deletes the value for the given key.
	// If the key is not found, it returns an error.
	Delete(ctx context.Context, key string) error
	// Sets the expiration time for the given key.
	Expire(ctx context.Context, key string, ttl time.Duration) error
	// Sets the value for the given key with a specific TTL.
	SetWithTTL(ctx context.Context, key string, value any, ttl time.Duration) error
}

Cache is the interface that defines the caching operations.

func NewCache

func NewCache(cacheCfg *CacheConfig) (Cache, func())

type CacheConfig

type CacheConfig struct {
	// local/remote, default is local
	Mode            string
	CacheName       string
	RemoteCacheAddr string
	// Default time to live for the key. See also ApplyTouch
	DefaultTTL  time.Duration
	MaxElements uint64
	// Set this to true in order to extend the TTL of the key
	ApplyTouch bool
}

type LocalCacheRistretto

type LocalCacheRistretto struct {
	// contains filtered or unexported fields
}

LocalCache is an implementation of Cache that uses Ristretto.

func NewLocalCacheRistretto

func NewLocalCacheRistretto(cacheCfg *CacheConfig) (*LocalCacheRistretto, func())

func (*LocalCacheRistretto) Delete added in v0.0.5

func (c *LocalCacheRistretto) Delete(ctx context.Context, key string) error

func (*LocalCacheRistretto) Expire added in v0.0.5

func (c *LocalCacheRistretto) Expire(ctx context.Context, key string, ttl time.Duration) error

func (*LocalCacheRistretto) Get

func (c *LocalCacheRistretto) Get(ctx context.Context, key string) (any, bool)

func (*LocalCacheRistretto) Set

func (c *LocalCacheRistretto) Set(ctx context.Context, key string, value any) error

func (*LocalCacheRistretto) SetWithTTL

func (c *LocalCacheRistretto) SetWithTTL(ctx context.Context, key string, value any, ttl time.Duration) error

type RemoteCacheValkey

type RemoteCacheValkey struct {
	// contains filtered or unexported fields
}

RemoteCache is an implementation of Cache that uses Redis.

func NewRemoteCacheValkey

func NewRemoteCacheValkey(cacheCfg *CacheConfig) (*RemoteCacheValkey, func())

func (*RemoteCacheValkey) Delete added in v0.0.5

func (c *RemoteCacheValkey) Delete(ctx context.Context, key string) error

func (*RemoteCacheValkey) Expire added in v0.0.5

func (c *RemoteCacheValkey) Expire(ctx context.Context, key string, ttl time.Duration) error

func (*RemoteCacheValkey) Get

func (c *RemoteCacheValkey) Get(ctx context.Context, key string) (interface{}, bool)

func (*RemoteCacheValkey) Set

func (c *RemoteCacheValkey) Set(ctx context.Context, key string, value interface{}) error

func (*RemoteCacheValkey) SetWithTTL

func (c *RemoteCacheValkey) SetWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error

Jump to

Keyboard shortcuts

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