UNPKG

with-simple-caching

Version:

A wrapper that makes it simple to add caching to any function

33 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withSimpleCachingOnDisk = void 0; const serde_fns_1 = require("serde-fns"); const simple_on_disk_cache_1 = require("simple-on-disk-cache"); const withSimpleCachingAsync_1 = require("./withSimpleCachingAsync"); /** * .what = a utility to make it easier to use on-disk caching * .why = * - embeds best practices of how to serialize and deserialize */ const withSimpleCachingOnDisk = (logic, options) => { return (0, withSimpleCachingAsync_1.withSimpleCachingAsync)(logic, { cache: (0, simple_on_disk_cache_1.createCache)({ directory: options.directory, expiration: options.expiration, }), serialize: { key: ({ forInput }) => (0, simple_on_disk_cache_1.castToSafeOnDiskCacheKey)({ procedure: options.procedure, execution: { input: forInput[0], // exclude the context }, }), value: serde_fns_1.asSerialJSON, }, deserialize: { value: (output) => (0, serde_fns_1.deSerialJSON)(output), }, }); }; exports.withSimpleCachingOnDisk = withSimpleCachingOnDisk; //# sourceMappingURL=withSimpleCachingOnDisk.js.map