GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cache/docs at main · ubgo/cache

Expand file tree

/

docs

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

docs

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
admin.md
admin.md
 
 
codecs.md
codecs.md
 
 
core-operations.md
core-operations.md
 
 
family.md
family.md
 
 
generics.md
generics.md
 
 
helpers.md
helpers.md
 
 
invalidation.md
invalidation.md
 
 
locker.md
locker.md
 
 
migration.md
migration.md
 
 
namespacing.md
namespacing.md
 
 
observability.md
observability.md
 
 
remember.md
remember.md
 
 
resilience.md
resilience.md
 
 
testing.md
testing.md
 
 

README.md

Outline

ubgo/cache — Feature Cookbook

Every exported feature of github.com/ubgo/cache (and its cachetest / admin sub-packages), documented one-by-one: what it is, real-world use cases, and a runnable Go snippet.

New here? Read the family overview to pick a backend, or the migration guide if you're coming from Ristretto / golang-lru / go-cache.

Start here

  1. Pick a backend module (cache-mem, cache-redis, cache-pg, cache-tiered, …). It implements cache.Cache.
  2. For raw bytes, use the core operations (Get/Set/Del/…).
  3. For typed load-through with stampede protection, use Remember or a Typed[T] view.
  4. Compose cross-cutting behavior by wrapping the cache: namespacing, observability, resilience.
  5. Unit-test consumers with cachetest.Mock; adapter authors run cachetest.Run.

All snippets use mem "github.com/ubgo/cache-mem" as a stand-in backend; swap in any adapter — behavior is identical (enforced by the conformance suite).

Pages

Page Covers
core-operations.md Cache interface (all 19 methods), Item, IterateOpts, Iterator, sentinel errors, Stats, EvictionCause, HitRatio
remember.md Remember, LoadFn, all RememberOpts, GetT/SetT, the envelope, RememberMulti/MultiLoadFn
generics.md Typed[T], NewTyped, its methods, Raw
codecs.md Codec, JSONCodec, GobCodec, RawCodec, DefaultCodec, EncryptedCodec, KeyProvider, StaticKey
namespacing.md Namespaced + scoped Flush
locker.md Locker, NewLock, Acquire/Refresh/Release, ErrLockNotAcquired
invalidation.md Invalidation, NewInProcInvalidation, InvalidateAll
observability.md Instrument, ObsHooks, OpEvent, KeyHash, HotKeyTracker, NamespaceStats, NamespaceFn, DefaultNamespaceFn
resilience.md NewCircuitBreaker, NewRetry, NewBulkhead, NewAuditLog, AuditEvent, AuditFunc, all options, stacking order
helpers.md Memoize, QueryKey, Once, ErrInFlight, Warm, WarmResult
admin.md admin.Mount, admin.Handler, admin.Options, routes, auth gating
testing.md cachetest.Run, Bench, Factory, Mock, Zipfian/NewZipfian, ScanGen, HitRate, Round

Capability matrix

I want to… Use Page
Store/read raw bytes Set / Get core
Cache a typed value with load-through Remember[T] remember
Keep hot keys from ever expiring WithRefreshAhead remember
Stay up when the DB is down WithStaleIfError remember
Stop re-querying missing rows WithNegativeTTL remember
Avoid a thundering-herd expiry WithJitter remember
Batch-load N keys in 2 round-trips RememberMulti[T] remember
A type-safe cache handle Typed[T] generics
Encrypt PII at rest in a shared store EncryptedCodec codecs
Share one backend across services Namespaced namespacing
A cross-pod mutex NewLock locker
Drop L1 copies when another node writes Invalidation invalidation
Metrics / tracing without a dependency Instrument + ObsHooks observability
Per-feature hit-rate NamespaceStats observability
Find the key that is 60% of traffic HotKeyTracker observability
Fail fast when the backend is sick NewCircuitBreaker resilience
Retry transient backend errors NewRetry resilience
Bound in-flight load on the backend NewBulkhead resilience
A compliance trail of writes NewAuditLog resilience
Memoize a function Memoize helpers
Idempotent webhooks/payments Once helpers
Preload a cold cache at startup Warm helpers
A collision-free cache key QueryKey helpers
Inspect cache in production over HTTP admin.Mount admin
Unit-test code that uses a cache cachetest.Mock testing
Verify a new adapter is correct cachetest.Run testing
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.