Skip to content

realcxj1989/cache-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cache-config

Install

$ npm i cache-config --save

Usage

import CacheConfig from 'cache-config';

const cacheConfig = new CacheConfig({
    mongodb: {
        url: 'mongodb://localhost:27017/test',
        options: {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        },
    },
    cacheType: "redis", // redis or memory
    redisConfig: {
        host: 'localhost',
        port: 6379,
        password: '',
        db: 0,
    },
    interval: 60 // seconds
});
await cacheConfig.init();
let config = await cacheConfig.getConfig('test'); // undefined
await cacheConfig.setConfig('test', {a: 1});
config = await cacheConfig.getConfig('test'); // '{"a": 1}'
await cacheConfig.setConfig('test', {a: 2});
config = await cacheConfig.getConfigToJsonObject('test'); // {a: 2}

Configuration

interface CacheConfigOptions {
  mongodb: {
    url: string;
    options: ConnectionOptions;
  };
  cacheType: "redis" | "memory";
  redisConfig?: RedisOptions;
  interval?: number;
}

Methods

interface CacheConfig {
  init(): Promise<void>;

  getConfig(key: string): Promise<string>;

  getConfigToJsonObject(key: string): Promise<any>;

  getLastConfig(key: string): Promise<string>;

  getLastConfigToJsonObject(key: string): Promise<any>;

  setConfig(key: string, value: any): Promise<void>;

  refreshConfig(key: string): Promise<void>;

  removeConfig(key: string): Promise<void>;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published