Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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.

License

Notifications You must be signed in to change notification settings

VictorQueiroz/cachecraft

Repository files navigation

CacheCraft

npm build license

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.

Features

  • Memorizer: Simple key-value caching.
  • MemorizerList: Caching for list-like data structures.
  • WeakMemorizer: WeakMap-based caching for objects.
  • LastKnownMemorizer: Caches the last known value.

Installation

npm install cachecraft

or

yarn add cachecraft

Usage

Memorizer

import { Memorizer } from 'cachecraft';
const memo = new Memorizer<number, string>((value) => value.toString());
console.log(memo.get(1)); // "1"

MemorizerList

import { MemorizerList } from 'cachecraft';
const memoList = new MemorizerList<number, string>((value) => value.toString());
console.log(memoList.get(1)); // "1"

WeakMemorizer

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

LastKnownMemorizer

import { LastKnownMemorizer } from 'cachecraft';
const lastKnownMemo = new LastKnownMemorizer<number, string>((value) => value.toString());
console.log(lastKnownMemo.get(1)); // "1"

Custom Comparers

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

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

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.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /