| /** | |
| * 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. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| import * as Cache from "../../Cache.js"; | |
| import * as Duration from "../../Duration.js"; | |
| import * as Effect from "../../Effect.js"; | |
| import { constant, identity } from "../../Function.js"; | |
| import * as Persistence from "./Persistence.js"; | |
| const TypeId = "~effect/persistence/PersistedCache"; | |
| /** | |
| * 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. | |
| * | |
| * @category constructors | |
| * @since 4.0.0 | |
| */ | |
| export const make = /*#__PURE__*/Effect.fnUntraced(function* (lookup, options) { | |
| const store = yield* (yield* Persistence.Persistence).make({ | |
| storeId: options.storeId, | |
| timeToLive: options.timeToLive | |
| }); | |
| const inMemory = yield* Cache.makeWith(Effect.fnUntraced(function* (key) { | |
| const exit = yield* store.get(key); | |
| if (exit) { | |
| return yield* exit; | |
| } | |
| const result = yield* Effect.exit(lookup(key)); | |
| yield* store.set(key, result); | |
| return yield* result; | |
| }), { | |
| timeToLive: options.inMemoryTTL ?? constant(Duration.seconds(10)), | |
| capacity: options.inMemoryCapacity ?? 1024, | |
| requireServicesAt: options.requireServicesAt | |
| }); | |
| return identity({ | |
| [TypeId]: TypeId, | |
| inMemory, | |
| get: key => Cache.get(inMemory, key), | |
| invalidate: key => Effect.flatMap(store.remove(key), () => Cache.invalidate(inMemory, key)) | |
| }); | |
| }); | |
| //# sourceMappingURL=PersistedCache.js.map |
Xet Storage Details
- Size:
- 1.94 kB
- Xet hash:
- 28d8062b2d0f63bd40878b1cb00af25ba1ef3945afe6f876edceac7949f904eb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.