Loading repository data…
Loading repository data…
VictorQueiroz / repository
TypeScript-based caching library that provides a collection of classes to easily memorize and cache the results of function calls. It offers a variety of caching mechanisms including simple key-value mapping, list-based caching, and weak reference caching.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
CacheCraft is a TypeScript-based caching library that provides a collection of classes to easily memorize and cache the results of function calls. It offers a variety of caching mechanisms including simple key-value mapping, list-based caching, and weak reference caching.
npm install cachecraft
or
yarn add cachecraft
import { Memorizer } from 'cachecraft';
const memo = new Memorizer<number, string>((value) => value.toString());
console.log(memo.get(1)); // "1"
import { MemorizerList } from 'cachecraft';
const memoList = new MemorizerList<number, string>((value) => value.toString());
console.log(memoList.get(1)); // "1"
import { WeakMemorizer } from 'cachecraft';
const weakMemo = new WeakMemorizer<object, string>((value) => JSON.stringify(value));
const obj = { key: 'value' };
console.log(weakMemo.get(obj)); // "{"key":"value"}"
import { LastKnownMemorizer } from 'cachecraft';
const lastKnownMemo = new LastKnownMemorizer<number, string>((value) => value.toString());
console.log(lastKnownMemo.get(1)); // "1"
You can also specify custom comparers for MemorizerList and LastKnownMemorizer:
import { MemorizerList, LastKnownMemorizer } from 'cachecraft';
const customComparer = (a: number, b: number) => a % 10 === b % 10;
const memoList = new MemorizerList<number, string>((value) => value.toString(), customComparer);
const lastKnownMemo = new LastKnownMemorizer<number, string>((value) => value.toString(), customComparer);
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.