---
library: "bootstrap"
slug: "Cache"
name: "Cache"
ref: "Cache#465f"
hash: "sema:Cache#mh:SHA-256:465f391fb70426b0ec99c724ecf5db549d4f2e8124c821530271124aa10e17f3"
type: "Data Structures"
layer: "Infrastructure"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/Cache"
---

# Cache

Keyed storage for reusing previously obtained values

Infrastructure · Data Structures

## Mechanism

A temporary keyed storage layer for keeping frequently accessed [Datum](https://semahash.org/vocabularies/bootstrap/patterns/Datum.md) or [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) alongside the inputs that produced them, so repeat lookups bypass re-computation. Read-through, write-behind, and invalidation discipline are descendant concerns; the foundation is the keyed lookup that returns a stored value if present.

## Invariants

- Consistency: Cache(Key) == Source(Key) if valid.
- Freshness: Expired items must not be returned.

## Preconditions

- Key is hashable
- Value is serializable

## Postconditions

- On a cache hit, the stored value for the requested key is returned without requiring recomputation.

## Failure modes

- Staleness: Serving outdated data after the source has changed.
- Thrashing: Frequent evictions due to insufficient size.

## Where this came from

—

## Builds on

- [State](https://semahash.org/vocabularies/bootstrap/patterns/State.md) (references)
- [Datum](https://semahash.org/vocabularies/bootstrap/patterns/Datum.md) (references)

## Used by

- [HeuristicSnap](https://semahash.org/vocabularies/bootstrap/patterns/HeuristicSnap.md) (references)
- [IdempotentWrite](https://semahash.org/vocabularies/bootstrap/patterns/IdempotentWrite.md) (references)
- [PathwayMemory](https://semahash.org/vocabularies/bootstrap/patterns/PathwayMemory.md) (references)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: Cache#465f
- Hash: sema:Cache#mh:SHA-256:465f391fb70426b0ec99c724ecf5db549d4f2e8124c821530271124aa10e17f3

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/Cache
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/Cache.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
