TS-Node-Cache is a TypeScript-based caching solution that's simple and lightweight. It supports data caching with optional expiration and callbacks. Similar to memory-cache but with modern implementation and TypeScript support.
- Stores any data type.
- Allows setting expiration time for entries.
- Supports custom callbacks on expiration.
- Debug mode for tracking cache activity.
- Serialize cache to/from JSON.
npm install @ebenezerdon/ts-node-cache
import { Cache } from '@ebenezerdon/ts-node-cache'
const cache = new Cache()
cache.put('myKey', 'myValue', 5000, () => console.log('Expired'))
let value = cache.get('myKey')
cache.del('myKey')
cache.clear()
cache.debug(true)
put(key: string, value: T, time?: number, timeoutCallback?: (key: string, value: T) => void): T
get(key: string): T | null
del(key: string): boolean
clear(): void
size(): number
debug(bool: boolean): void
hits(): number
misses(): number
keys(): string[]
exportJson(): string
importJson(jsonToImport: string, options?: { skipDuplicates?: boolean }): number
To contribute:
- Fork & Clone: Fork the repo and clone it locally.
- Make Changes: Work on your changes.
- Build: Run
npm run build
to build the project. - Test: Ensure your changes don't break anything.
- Submit a PR: Push your changes and submit a pull request.
This project is licensed under the ISC License - see the LICENSE file for details.