@junaid1460/simple-redis-cache

1.0.13 • Public • Published

Simple redis cache

NPM version Cache data easily with a simple wrap.

npm i @junaid1460/simple-redis-cache

Usage

typescript:
import { RedisCache } from "@junaid1460/simple-redis-cache";

const cache = new RedisCache({
    host: "localhost",
});

function myFunc(x: number, y: number) {
    return cache.cached({
        expiresAfter: 10, // seconds
        keys: [x, y], // list of number or string to construct key
        // closure
        func: async () => {
            return x * y;
        },
    });
}

myFunc(1, 2).get().then((e) => console.log(e.hit, e.data));
Javascript:
const redisCache = require('@junaid1460/simple-redis-cache')
const cache = new redisCache.RedisCache({
    host: 'localhost'
})


function myFunc(x, y) {
    return cache.cached({
        expiresAfter: 10, // seconds
        keys: [x, y], // list of number or string to construct key
        // closure
        func: async () => {
            return x * y;
        },
    });
}

myFunc(1, 2).delete().then((e) => console.log());

Package Sidebar

Install

npm i @junaid1460/simple-redis-cache

Weekly Downloads

0

Version

1.0.13

License

MIT

Unpacked Size

9.39 kB

Total Files

6

Last publish

Collaborators

  • junaid1460