3.6.6 • Published 9 months ago

@qelos/cache-manager v3.6.6

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

@qelos/cache-manager

cache manager library for backend services, using redis or internal memory.

Simple Installation Example

Install

$ npm install @qelos/cache-manager
import {createCacheManager} from '@qelos/cache-manager';
import {redisUrl} from './config';

const cacher = redisUrl ?
  require('@qelos/cache-manager/dist/redis-cache').createRedisCache(redisUrl) :
  require('@qelos/cache-manager/dist/memory-cache').createMemoryCache()

const cacheManager = createCacheManager(cacher);

Get item from cache

const value = await cacheManager.getItem('your-cache-key');

Set item to cache

The value must in a string

await cacheManager.setItem('your-cache-key', 'new value to store in cache');

Wrap a fallback to get an item

In this method, you can specify a key. If the key doesn't exist inside the cache store, it will fall back to the function, return its value and store it inside the cache store.

const value = await cacheManager.wrap('your-cache-key', async () => {
  const data = await someDatabase.query('select * from MyTable where id = X')
  return JSON.stringify(data);
});

Custom cache options

await cacheManager.setItem('your-cache-key', 'new value to store in cache', {
  ttl: 1000 // in seconds
});
3.6.6

9 months ago

3.4.1

1 year ago

3.4.0

1 year ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.34

2 years ago

3.0.1

2 years ago