Documentation
¶
Index ¶
- type CacheValue
- type KvCache
- func (c *KvCache) Get(ctx context.Context, key string, opts ...kvcachehelper.CacheGetOptions) (any, bool)
- func (c *KvCache) Keys(ctx context.Context, opts ...kvcachehelper.CacheKeysOptions) ([]string, error)
- func (c *KvCache) Remove(ctx context.Context, key string, opts ...kvcachehelper.CacheRemoveOptions) bool
- func (c *KvCache) Set(ctx context.Context, key string, value any, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheValue ¶
type KvCache ¶
type KvCache struct {
// contains filtered or unexported fields
}
func NewKvCache ¶
func NewKvCache(opts ...kvcachehelper.CacheOptions) *KvCache
NewKvCache instantiates a new Cache and sets the default values. The default expiration time is set to 6 hours from the current time. The expiration time can be overridden by passing an expirationTime option. Example: cache := NewKvCache(ExpirationTime: time.Now().Add(1 * time.Hour))
func (*KvCache) Get ¶
func (c *KvCache) Get(ctx context.Context, key string, opts ...kvcachehelper.CacheGetOptions) (any, bool)
Get retrieves a value from the cache. If the key does not exist or the value has expired, it will return false.
func (*KvCache) Keys ¶ added in v1.1.3
func (c *KvCache) Keys(ctx context.Context, opts ...kvcachehelper.CacheKeysOptions) ([]string, error)
Keys returns all keys in the cache. The error return value is included for consistency with other methods and to allow for potential future use, even though the current implementation always returns nil.
func (*KvCache) Remove ¶
func (c *KvCache) Remove(ctx context.Context, key string, opts ...kvcachehelper.CacheRemoveOptions) bool
Remove removes a key-value pair from the cache.
func (*KvCache) Set ¶ added in v0.1.9
func (c *KvCache) Set(ctx context.Context, key string, value any, opts ...kvcachehelper.CacheSetOptions)
Set adds a new key-value pair to the cache. If the key already exists, it will be overwritten.