cache-config
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

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>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i cache-config

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

18.2 kB

Total Files

12

Last publish

Collaborators

  • realcxj1989