PersistedCache
Combines in-memory caching with durable storage for Persistable requests.
A PersistedCache checks a process-local Cache, then a named Persistence store, before running the supplied lookup. It stores the lookup Exit, so expensive or idempotent results can be reused across fibers, process restarts, or workers that share the same backing store.
Constructors
Signature
declare const make: <
K extends Persistable.Any,
R = never,
ServiceMode extends "lookup" | "construction" = never,
>(
lookup: (key: K) => Effect.Effect<Persistable.Success<K>, Persistable.Error<K>, R>,
options: {
readonly inMemoryCapacity?: number;
readonly inMemoryTTL?: Persistable.TimeToLiveFn<K>;
readonly requireServicesAt?: ServiceMode;
readonly storeId: string;
readonly timeToLive: Persistable.TimeToLiveFn<K>;
},
) => Effect.Effect<
PersistedCache<K, "lookup" extends ServiceMode ? R : never>,
never,
"lookup" extends ServiceMode ? never : R | Persistence.Persistence | Scope.Scope
>;Models
PersistedCache interface
Added in v4.0.0
Source
Cache that combines an in-memory Cache with a persisted backing store.
Signature
interface PersistedCache<K extends Persistable.Any, out R = never> {
readonly "~effect/persistence/PersistedCache": "~effect/persistence/PersistedCache";
readonly get: (
key: K,
) => Effect<Success<K>, SchemaError | PersistenceError | Error<K>, R | Services<K>>;
readonly inMemory: Cache<
K,
Success<K>,
SchemaError | PersistenceError | Error<K>,
R | Services<K>
>;
readonly invalidate: (key: K) => Effect<void, PersistenceError>;
}
Creates a persisted cache for
Persistablerequest keys.Details
The cache reads persisted exits before running the lookup, stores lookup exits with the configured persistent TTL, and also keeps a scoped in-memory cache with its own capacity and TTL.