Skip to content

iocium/cachekit

Repository files navigation

@iocium/cachekit

A flexible caching adapter with pluggable backends for Node.js and serverless environments


✨ Features

  • ✅ Modular backend support: Memory, Redis, Memcached, Cloudflare KV, Cloudflare D1
  • ✅ TTL and automatic expiry logic
  • ✅ Works in Node.js and edge/serverless environments
  • ✅ Fully typed and tested with 100% coverage

📦 Installation

npm install @iocium/cachekit

🚀 Usage

import { createCacheKit, MemoryBackend } from '@iocium/cachekit';

const cache = createCacheKit();
await cache.set('key', 'value', 5000); // TTL in ms
const result = await cache.get('key');

🧩 Using Custom Backends

Redis

import { RedisBackend } from '@iocium/cachekit';
import { createClient } from 'redis';

const client = createClient();
await client.connect();
const cache = createCacheKit({ backend: new RedisBackend(client) });

Memcached

import { MemcachedBackend } from '@iocium/cachekit';
import Memcached from 'memcached';

const memcached = new Memcached('localhost:11211');
const cache = createCacheKit({ backend: new MemcachedBackend(memcached) });

Cloudflare KV (in Workers)

import { KVBackend } from '@iocium/cachekit';
const cache = createCacheKit({ backend: new KVBackend(MY_KV_NAMESPACE) });

Cloudflare D1 (in Workers)

import { D1Backend } from '@iocium/cachekit';
const cache = createCacheKit({ backend: new D1Backend(MY_D1_INSTANCE) });

D1 requires a cache table:

CREATE TABLE cache (
  key TEXT PRIMARY KEY,
  value TEXT,
  expiresAt INTEGER
);

🧪 Testing

npm run test
npm run test:coverage

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


Made with 💙 by Iocium

About

A flexible caching adapter with pluggable backends for Node.js and serverless environments

Resources

License

Stars

Watchers

Forks

Packages

No packages published