Documentation ¶
Index ¶
- type Cache
- type CacheConfig
- type LocalCacheRistretto
- func (c *LocalCacheRistretto) Delete(ctx context.Context, key string) error
- func (c *LocalCacheRistretto) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (c *LocalCacheRistretto) Get(ctx context.Context, key string) (string, bool)
- func (c *LocalCacheRistretto) Set(ctx context.Context, key string, value string) error
- func (c *LocalCacheRistretto) SetWithTTL(ctx context.Context, key string, value string, ttl time.Duration) error
- type RemoteCacheValkey
- func (c *RemoteCacheValkey) Delete(ctx context.Context, key string) error
- func (c *RemoteCacheValkey) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (c *RemoteCacheValkey) Get(ctx context.Context, key string) (string, bool)
- func (c *RemoteCacheValkey) Set(ctx context.Context, key string, value string) error
- func (c *RemoteCacheValkey) SetWithTTL(ctx context.Context, key string, value string, ttl time.Duration) error
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) (string, bool) // Sets the value for the given key. // If the key already exists, it returns an error. Set(ctx context.Context, key string, value string) 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 string, ttl time.Duration) error }
Cache is the interface that defines the caching operations.
func NewCache ¶
func NewCache(cacheCfg *CacheConfig) (Cache, error, func())
NewCache creates a new cache instance based on the provided configuration.
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 }
CacheConfig is the configuration for the cache.
type LocalCacheRistretto ¶
type LocalCacheRistretto struct {
// contains filtered or unexported fields
}
LocalCacheRistretto is an implementation of Cache that uses Ristretto. It provides a local in-memory caching solution.
func NewLocalCacheRistretto ¶
func NewLocalCacheRistretto(cacheCfg *CacheConfig) (*LocalCacheRistretto, error, func())
NewLocalCacheRistretto creates a new instance of LocalCacheRistretto. It initializes the Ristretto cache with the provided configuration.
func (*LocalCacheRistretto) Delete ¶ added in v0.0.5
func (c *LocalCacheRistretto) Delete(ctx context.Context, key string) error
Delete removes the key from the cache.
func (*LocalCacheRistretto) Expire ¶ added in v0.0.5
Expire removes the key from the cache. Note: Ristretto doesn't support updating TTL, so we simply delete the key.
func (*LocalCacheRistretto) Get ¶
Get retrieves a value from the cache for the given key. It returns the value and a boolean indicating whether the key was found.
func (*LocalCacheRistretto) Set ¶
Set stores a value in the cache for the given key. If a TTL is set, it calls SetWithTTL instead.
func (*LocalCacheRistretto) SetWithTTL ¶
func (c *LocalCacheRistretto) SetWithTTL(ctx context.Context, key string, value string, ttl time.Duration) error
SetWithTTL stores a value in the cache for the given key with a specified TTL.
type RemoteCacheValkey ¶
type RemoteCacheValkey struct {
// contains filtered or unexported fields
}
RemoteCacheValkey is an implementation of Cache that uses Valkey as a remote cache.
func NewRemoteCacheValkey ¶
func NewRemoteCacheValkey(cacheCfg *CacheConfig) (*RemoteCacheValkey, error, func())
NewRemoteCacheValkey creates a new instance of RemoteCacheValkey. It initializes the Valkey client with the provided configuration.
func (*RemoteCacheValkey) Delete ¶ added in v0.0.5
func (c *RemoteCacheValkey) Delete(ctx context.Context, key string) error
Delete removes the key from the cache.
func (*RemoteCacheValkey) Expire ¶ added in v0.0.5
Expire sets the expiration time for the given key.
func (*RemoteCacheValkey) Get ¶
Get retrieves a value from the cache for the given key. It returns the value and a boolean indicating whether the key was found.
func (*RemoteCacheValkey) Set ¶
Set stores a value in the cache for the given key. If a TTL is set, it calls SetWithTTL instead.
func (*RemoteCacheValkey) SetWithTTL ¶
func (c *RemoteCacheValkey) SetWithTTL(ctx context.Context, key string, value string, ttl time.Duration) error
SetWithTTL stores a value in the cache for the given key with a specified TTL.