driver agnostic caching implementation
npm install @devbro/neko-cacheA flexible and customizable caching solution for Node.js and bun applications with support for multiple providers.
``bash`
npm install @devbro/neko-cache
- Multiple cache providers (Redis, Memory, etc.)
- Simple and intuitive API
- TypeScript support
- Async/await support
- TTL (Time To Live) support
- Key prefixing and namespacing
`ts
import { CacheManager } from '@devbro/neko-cache';
// Create a cache instance
const cache = new CacheManager();
// Set a value
await cache.set('key', 'value', 3600); // TTL in seconds
// Get a value
const value = await cache.get('key');
// Delete a value
await cache.delete('key');
// Clear all cache
await cache.clear();
`
`ts
import { CacheManager, MemoryProvider } from '@devbro/neko-cache';
// Create cache with custom provider
const cache = new CacheManager({
provider: new MemoryProvider(),
prefix: 'myapp:',
});
// Check if key exists
const exists = await cache.has('key');
// Get multiple values
const values = await cache.getMany(['key1', 'key2', 'key3']);
// Set multiple values
await cache.setMany(
{
key1: 'value1',
key2: 'value2',
},
3600
);
// Delete multiple keys
await cache.deleteMany(['key1', 'key2']);
`
#### Methods
- get(key: string): Promise - Retrieve a value from cacheset(key: string, value: any, ttl?: number): Promise
- - Store a value in cachehas(key: string): Promise
- - Check if a key existsdelete(key: string): Promise
- - Remove a value from cacheclear(): Promise
- - Clear all cached valuesgetMany(keys: string[]): Promise
- - Retrieve multiple valuessetMany(items: Record
- - Store multiple valuesdeleteMany(keys: string[]): Promise
-
MIT
Contributions are welcome! Please feel free to submit a Pull Request.