Repository navigation
v0.5.0
Caching that can be switched off, and view stats from the cache
Disabled views. NewView accepts a nil cache and opens a view that stores nothing. It is meant for configurations where a TTL of zero means "do not cache", so code keeps calling GetOrLoad either way. The loader runs on every call, concurrent callers still share one call, and nothing is kept, ErrNotFound included. Lookups are misses, Delete reports false, and writes return the new ErrDisabled. NewView(nil, …) used to panic.
Cache.ViewStats() returns counters for every view opened on the cache, keyed by view name, so a metrics exporter needs no registry of its own. View counters now belong to the name rather than the instance: views opened with the same name on the same cache share one set, as they already share keys.
Honest cost for negative entries. Under a byte budget, a "does not exist" entry is charged 128 bytes plus the length of a string key, instead of a flat 64. BenchmarkNegativeEntryMemory measures 115–133 bytes before the key for a Cache[string, any], so a flood of lookups for missing ids used two to three times the memory the budget reported. Budgets now fill with negative entries sooner, and a shard budget below roughly 130 bytes rejects them with ErrTooLarge.
Documentation. Options.Loader no longer describes a stale-publication race that 0.4.0 removed. The text of ErrNoLoader now names both loader sources; compare with errors.Is, not with the string.
See CHANGELOG.md for migration notes.
Install:
go get github.com/andared/sanecache@v0.5.0