Documentation
¶
Index ¶
- type MemCache
- func (m *MemCache) Close() error
- func (m *MemCache) Del(ctx context.Context, keys ...string) error
- func (m *MemCache) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (m *MemCache) Get(ctx context.Context, key string) (string, error)
- func (m *MemCache) Incr(ctx context.Context, key string, delta int64) (int64, error)
- func (m *MemCache) Set(ctx context.Context, key, val string, ttl time.Duration) error
- func (c *MemCache) String() string
- type MemCacheOptions
- type Memory
- func (m *Memory) Close() error
- func (m *Memory) Decrease(key string) error
- func (m *Memory) Del(key string) error
- func (m *Memory) Expire(key string, dur time.Duration) error
- func (m *Memory) Get(key string) (string, error)
- func (m *Memory) HashDel(hk, key string) error
- func (m *Memory) HashGet(hk, key string) (string, error)
- func (m *Memory) Increase(key string) error
- func (m *Memory) Set(key string, val interface{}, expire int) error
- func (*Memory) String() string
- type Message
- func (m *Message) GetID() string
- func (m *Message) GetPrefix() (prefix string)
- func (m *Message) GetStream() string
- func (m *Message) GetValues() map[string]interface{}
- func (m *Message) SetID(id string)
- func (m *Message) SetPrefix(prefix string)
- func (m *Message) SetStream(stream string)
- func (m *Message) SetValues(values map[string]interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemCache ¶
type MemCache struct {
// contains filtered or unexported fields
}
MemCache is an in-process storage.Cache.
func NewMemCache ¶
func NewMemCache() *MemCache
func NewMemCacheWithOptions ¶ added in v2.2.0
func NewMemCacheWithOptions(o MemCacheOptions) *MemCache
NewMemCacheWithOptions builds a cache from an explicit configuration.
func NewMemCacheWithSweep ¶
NewMemCacheWithSweep sets the sweep interval. Zero or less starts no sweeper, leaving expiry entirely lazy.
type MemCacheOptions ¶ added in v2.2.0
type MemCacheOptions struct {
// SweepInterval is how often expired entries are collected. Zero or less
// starts no sweeper, leaving expiry entirely lazy.
SweepInterval time.Duration
// MaxEntries caps the number of entries held. Zero means
// defaultMaxEntries; a negative value means no limit, which is only
// appropriate when the keyspace is known to be bounded by something else.
//
// The cap is enforced per shard, so the effective total is rounded down to
// a multiple of shardCount.
MaxEntries int
}
MemCacheOptions configures NewMemCacheWithOptions.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func NewMemory ¶
func NewMemory() *Memory
NewMemory returns a cache that sweeps expired entries every defaultCleanupInterval.
Lazy deletion on Get is not enough to reclaim memory: a key that is written and never read again stays forever, so a long-running process only grows (issue #31).
Call Close when the instance is not process-wide (repeated construction in tests, for example). Skipping it does not leak without bound — each instance owns exactly one goroutine.
func NewMemoryWithCleanupInterval ¶
NewMemoryWithCleanupInterval sets the sweep interval. A value of zero or less starts no sweeper, falling back to purely lazy expiry.
func (*Memory) Close ¶
Close stops the sweeper. It is safe to call more than once.
It is deliberately not part of storage.AdapterCache, to avoid breaking existing implementations; holders of the interface can reach it by assertion:
if c, ok := cache.(interface{ Close() error }); ok {
_ = c.Close()
}