iet-cache
core contract official
Defines one typed cache contract; storage, eviction, and serialization belong to implementations.
CoreFeaturesIntegrationsStacksTooling
Used byiet-auth-session-cacheiet-cache-memoryiet-rate-limit
iet-cachecontractCache contractDepends oniet-corecontract
How to use it
iet-cache defines typed cache contracts: Cache (with get, put, invalidate, prefix invalidation, atomic window counters, and get_or_load), plus CacheKey::scoped for collision-free keys. Storage, serialization, and scope live in adapters such as iet-cache-memory; this crate only fixes the shape.
// examples/htmx-starter/crates/task-impl-timescale/src/service.rs
use ;
use TransactionSession;
// `page: u32` is the request parameter; include scope, operation, and query args.
let page_key = page.to_string;
let key = scoped;
let mut session = self.database.session;
let transaction_active = session.state != Idle;
let result = self
.cache
.get_or_load
.await?;
- A zero TTL removes the key; a backend error is never reported as a cache miss.
invalidate_prefixcallers must not treat success as done until matching keys are unreadable.
How it works
get_or_load consults Cache::get first; on a miss it runs the loader once and stores the value with Cache::put, so concurrent readers of the same CacheKey do not each hit the backend.
sequenceDiagram
participant C as "Caller"
participant H as "Cache"
participant L as "loader closure"
C->>H: "get_or_load key ttl transaction_active"
alt hit
H-->>C: "cached value"
else miss
H->>L: "load"
L-->>H: "value"
H->>H: "put key value ttl"
H-->>C: "value"
endCore contract
This page is the crate reference. For the framework-wide runtime and trait model, read Architecture.
What it implements
- Defines the traits other crates implement:
Cache.
What's inside
Modules
src/lib.rs
Public API
(root)
- struct
CacheKey - struct
CounterWindow pub fn scoped(namespace: &str, operation: &str, parts: &[&str]) -> Self— Include visibility scope, operation and all query arguments. Never credentials.- trait
Cache— One concrete value type per cache capability. No serialization requirement. Errors are not misses. Zero TTL removes the key. Read-through calls bypass storage during transactions. Implementations must make prefix invalidation complete before returning success.
Depends on
Used by
In this repository
examples/htmx-starter
Source: crates/core/iet-cache