@bolt.tech/cache-manager
v1.0.25
Published
This is an internal module of BOLT for handling connections to Redis.
Downloads
244
Keywords
Readme
BOLT Cache Manager
This is an internal module of BOLT for handling connections to Redis.
Installation
npm i --save @bolt.tech/cache-manager
Initialise CacheManager
Create a
cachemanger.ts
file and paste below template to initialise your cache manager.
import * as dotenv from "dotenv";
dotenv.config();
import CacheManager from "@bolt.tech/cache-manager";
const db = new CacheManager(process.env.PARAMSTORE_PATH, process.env.NODE_ENV_LOCAL);
export { db };
Class CacheManager
takes two arguments as inputs, paramstorePath
and isLocal
.
paramstorePath
can be dev
or prod
.
Set isLocal
as "TRUE"
in case you want to connect to redis running on your local instance.
Basic Usage
Class CacheManager
has certain set of functions defined which can be used to perform actions on Redis/Elasticache.
To get a key from redis
import {db} from "cacheManager.ts"
db.get('key');
To set a key in redis
import {db} from "cacheManager.ts"
db.set('key', 'hello');
db.set()
has a default expiry of 240 seconds or 4 mins. To set custom expiry on your keys, you can pass an optional 3rd argument as expiry of key in seconds in this function.
db.set('key', 'custom expiry', 3000);