Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

PersistedCache unstable

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.

2 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a persisted cache for Persistable request 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.

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 unstable
Since v4.0.0

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>;
}