Documentation
¶
Overview ¶
Package cachememory provides a bounded, concurrency-safe LRU cache adapter. Entry/byte accounting is not a heap cap. Expiration is lazy at StaleAt, and Stats does not sweep. Close releases retained entries; no janitor is started. Clock callbacks run under the mutex; observers run synchronously after it.
Index ¶
- type Backend
- func (b *Backend) Close() error
- func (b *Backend) Delete(ctx context.Context, key string) (bool, error)
- func (b *Backend) Get(ctx context.Context, key string) (cache.Record, bool, error)
- func (b *Backend) Set(ctx context.Context, key string, record cache.Record, ...) (bool, error)
- func (b *Backend) Stats() Stats
- type Config
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a bounded concurrency-safe LRU backend.
func (*Backend) Set ¶
func (b *Backend) Set( ctx context.Context, key string, record cache.Record, condition cache.Condition, ) (bool, error)
Set atomically applies condition and stores a cloned record. A structurally valid past hard deadline is admitted and removed lazily on access. Size means key+payload bytes, not heap overhead. Eviction may remove multiple entries.
type Config ¶
type Config struct {
// MaxEntries bounds retained entries, not all allocations or initial map overhead.
MaxEntries int
// MaxBytes bounds retained key+payload bytes, excluding map/list/runtime overhead.
MaxBytes int
// Clock is retained and called under the backend mutex; it must not re-enter.
Clock cache.Clock
// Observer optionally receives removal events after unlocking; it may block the call.
Observer cache.Observer
}
Config defines hard entry and retained-byte limits for a Backend.
type Stats ¶
type Stats struct {
// Entries counts retained entries, including expired entries not yet touched.
Entries int
// Bytes counts retained key+payload bytes, not total process memory.
Bytes int
// Evictions counts capacity removals since construction, not explicit deletes.
Evictions uint64
// Expirations counts lazy hard-deadline removals since construction.
Expirations uint64
}
Stats is a snapshot of retained state and cumulative removals.