cache
Minified4.14 KBMinzipped1.21 KBFunctional cache utilities.
Example
ts
import { Cache } from "@monstermann/cache";
// Create a LRU cache with a maximum of 100 items
const cache = Cache.LRU<string, number>({ max: 100 });
// Set values
Cache.set(cache, "foo", 1);
Cache.set(cache, "bar", 2);
// Get values
const foo = Cache.get(cache, "foo"); // 1
const missing = Cache.get(cache, "unknown"); // undefined
// Get or compute and cache a value
const score = Cache.getOrElse(cache, "baz", (c) => {
return Cache.set(c, "baz", 3);
});
// Check existence
Cache.has(cache, "foo"); // true
// Remove values
Cache.remove(cache, "bar");Installation
sh
npm install @monstermann/cachesh
pnpm add @monstermann/cachesh
yarn add @monstermann/cachesh
bun add @monstermann/cacheTree-shaking
Installation
sh
npm install -D @monstermann/unplugin-cachesh
pnpm -D add @monstermann/unplugin-cachesh
yarn -D add @monstermann/unplugin-cachesh
bun -D add @monstermann/unplugin-cacheUsage
ts
// vite.config.ts
import cache from "@monstermann/unplugin-cache/vite";
export default defineConfig({
plugins: [cache()],
});ts
// rollup.config.js
import cache from "@monstermann/unplugin-cache/rollup";
export default {
plugins: [cache()],
};ts
// rolldown.config.js
import cache from "@monstermann/unplugin-cache/rolldown";
export default {
plugins: [cache()],
};ts
// webpack.config.js
const cache = require("@monstermann/unplugin-cache/webpack");
module.exports = {
plugins: [cache()],
};ts
// rspack.config.js
const cache = require("@monstermann/unplugin-cache/rspack");
module.exports = {
plugins: [cache()],
};ts
// esbuild.config.js
import { build } from "esbuild";
import cache from "@monstermann/unplugin-cache/esbuild";
build({
plugins: [cache()],
});