Documentation
¶
Overview ¶
Package memory is an in-process cache backend. It stores values in a sync-protected map, evicts on TTL check, and is safe for concurrent use.
Memory is the default backend for tests and single-process applications that do not need cross-process cache coherence. For multi-instance deployments use hex/cache/redis or hex/cache/memcached (opt-in).
Index ¶
- type Cache
- func (c *Cache) Clear(context.Context) error
- func (c *Cache) Delete(_ context.Context, key string) error
- func (c *Cache) Get(_ context.Context, key string) ([]byte, bool, error)
- func (c *Cache) Has(ctx context.Context, key string) (bool, error)
- func (c *Cache) Increment(_ context.Context, key string, delta int64) (int64, error)
- func (c *Cache) Len() int
- func (c *Cache) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
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
}
Cache is an in-memory cache implementation.
func WithClock ¶
WithClock returns a Cache using now for time. Intended for tests that need to advance time deterministically instead of sleeping.
func (*Cache) Increment ¶
Increment atomically adds delta to the value at key. Absent keys start from zero and take no expiration. Non-numeric existing values return an error.