@rhangai/cache
TypeScript icon, indicating that this package has built-in type declarations

0.9.2 • Public • Published

@rhangai/cache

Simple cache structure

yarn add @rhangai/cache

Simple Usage

import { Cache } from '@rhangai/cache';

const cache = new Cache<number, User>({
	duration: 30000,
	durationUntilCold: 25000,
});
function loadUser(id: number) {
	/*
		The cache will return the same item as long as the duration is less than the time given
		If the cache is cold (not expired, only old). The old value will be returned but a new value will be requested
	*/
	return cache.get(id, async () => {
		const user = await loadUserFromDb(id);
		return user;
	});
}
const user = await loadUser(1);

Readme

Keywords

Package Sidebar

Install

npm i @rhangai/cache

Weekly Downloads

1

Version

0.9.2

License

MIT

Unpacked Size

33.9 kB

Total Files

21

Last publish

Collaborators

  • rhangai