Skip to content

manizm/cachinator

Repository files navigation

Cachinator tests codecov Code Style: Google

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.

Features

  • 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

Installation

Use pnpm to install dependencies:

pnpm install

Running Tests

The test suite compiles the TypeScript sources and runs Jest. Execute:

pnpm test

All tests should pass (58 tests across six suites). The lint step that follows may fail on newer Node versions.

Example

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()));

Node Redis Example

To run the Redis example you need a running Redis server and the node-redis package:

pnpm add redis

example/RedisExample.ts demonstrates using RedisStore with a real client.

Todo

  • add actual tests
  • get 100% code coverage
  • create detailed readme
  • create cache store for redis client

About

A cache service factory written in nodejs and typescript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •