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 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 ¶ added in v1.8.0
type MemCache struct {
// contains filtered or unexported fields
}
MemCache is an in-process storage.Cache.
A single mutex guards the map. Incr must be atomic, and sync.Map cannot express a read-modify-write, which is how the previous implementation lost updates under concurrency.
func NewMemCache ¶ added in v1.8.0
func NewMemCache() *MemCache
func NewMemCacheWithSweep ¶ added in v1.8.0
NewMemCacheWithSweep sets the sweep interval. Zero or less starts no sweeper, leaving expiry entirely lazy.
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 ¶ added in v1.8.0
NewMemoryWithCleanupInterval sets the sweep interval. A value of zero or less starts no sweeper, falling back to purely lazy expiry.
func (*Memory) Close ¶ added in v1.8.0
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()
}