Documentation
¶
Index ¶
- type Cache
- func (c *Cache) AddPrefix(key string) string
- func (c *Cache) Client() any
- func (c *Cache) Close() (err error)
- func (c *Cache) DecrFloat(ctx context.Context, key string, value float64) (float64, error)
- func (c *Cache) DecrInt(ctx context.Context, key string, value int64) (int64, error)
- func (c *Cache) Delete(ctx context.Context, keys ...string) (int64, error)
- func (c *Cache) Get(ctx context.Context, key string, def ...any) cache.Result
- func (c *Cache) GetSet(ctx context.Context, key string, fn cache.SetValueFunc) cache.Result
- func (c *Cache) Has(ctx context.Context, key string) (bool, error)
- func (c *Cache) IncrFloat(ctx context.Context, key string, value float64) (float64, error)
- func (c *Cache) IncrInt(ctx context.Context, key string, value int64) (int64, error)
- func (c *Cache) Set(ctx context.Context, key string, value any, expiration ...time.Duration) error
- type Option
- func WithAddrs(addrs ...string) Option
- func WithClient(client *memcache.Client) Option
- func WithMaxExpiration(maxExpiration time.Duration) Option
- func WithMinExpiration(minExpiration time.Duration) Option
- func WithNilExpiration(nilExpiration time.Duration) Option
- func WithNilValue(nilValue string) Option
- func WithPrefix(prefix string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func NewCache ¶
NewCache returns a new Memcache-backed Cache. The optional opts override the default configuration.
func (*Cache) Close ¶
Close closes the cache. It reports errors.ErrCacheClosed when the cache is already closed. The built-in client is closed only when it was created by NewCache.
func (*Cache) DecrFloat ¶
DecrFloat decrements the float stored at key by value and returns the resulting value. Since Memcache does not support floats, the decrement is implemented through integer decrements.
func (*Cache) DecrInt ¶
DecrInt decrements the integer stored at key by value and returns the resulting value.
func (*Cache) Delete ¶
Delete removes the given keys and reports how many keys were actually deleted.
func (*Cache) Get ¶
Get returns the value of key. The optional def is returned when the entry does not exist.
func (*Cache) GetSet ¶
GetSet returns the value of key, generating it with fn and storing it when the entry does not exist.
func (*Cache) IncrFloat ¶
IncrFloat increments the float stored at key by value and returns the resulting value. Since Memcache does not support floats, the increment is implemented through integer increments.
type Option ¶
type Option func(o *options)
func WithAddrs ¶
WithAddrs sets the connection addresses. It accepts one or more Memcache node addresses.
func WithClient ¶
WithClient sets an external client. The external client takes precedence over the built-in one.
func WithMaxExpiration ¶
WithMaxExpiration sets the maximum expiration time. Non-positive values are ignored.
func WithMinExpiration ¶
WithMinExpiration sets the minimum expiration time. Non-positive values are ignored.
func WithNilExpiration ¶
WithNilExpiration sets the expiration time of a cached nil. Non-positive values are ignored.
func WithNilValue ¶
WithNilValue sets the placeholder value that marks a cached nil.