Skip to content

daaxar/cache

Repository files navigation

Yet another cache wrapper function

DEVELOP | MAIN

Create a cache wrapper instance

const { Cache } = require('@daaxar/cache');

const cacheOptions = { expiresAt: 2 };
const cache = Cache(cacheOptions);

Use cache wrapper on a function

const foo = async () => Date.now();

const cacheableFoo = cache(foo);

const promise = cacheableFoo();

promise.then((value) => console.log({ value }));

Using the file system repository (default)

const { filesystem } = require('../src/repository');

const repository = filesystem({ folder: `${__dirname}/.cache` });

const cache = Cache({
    expiresAt: 2,   // Expire at 2 seconds. Default is 30 seconds
    repository,
});

Using memory repository

const { memory } = require('../src/repository');

const repository = memory();

const cache = Cache({
    expiresAt: 2,
    repository,
});

About

Yet another cache wrapper function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages