Skip to content

junaid1460/simple-redis-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published