A cache service factory written in Node.js and TypeScript. It ships with an in-memory cache strategy and a container for managing multiple stores.
- CacheContainer – register and retrieve multiple stores by key
- MemoryStore – in-memory cache with TTL support and hit/miss statistics
- RedisStore – wrapper around a Redis client with TTL support and direct client access
- Custom errors for invalid arguments, duplicate keys and size limits
- Fully typed API with tests covering core behaviour
Use pnpm to install dependencies:
pnpm installThe test suite compiles the TypeScript sources and runs Jest. Execute:
pnpm testAll tests should pass (58 tests across six suites). The lint step that follows may fail on newer Node versions.
See example/MemCacheTest.ts for a small demonstration. In short:
import {CacheContainer, MemoryStore} from './src';
const container = new CacheContainer();
container.addStore('names', new MemoryStore({defaultTTL: 0, maxKeys: 0, ttlCheckTimer: 0}));
const store = container.getStore('names') as MemoryStore<{name: string}, Date>;
store.set(new Date(), {name: 'ali'});
console.log(store.get(new Date()));To run the Redis example you need a running Redis server and the node-redis package:
pnpm add redisexample/RedisExample.ts demonstrates using RedisStore with a real client.
add actual tests- get 100% code coverage
- create detailed readme
create cache store for redis client