1.0.11 • Published 2 years ago
@ebenezerdon/ts-node-cache v1.0.11
TS-Node-Cache
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.
Features
- 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.
Installation
npm install @ebenezerdon/ts-node-cacheUsage
Import and Create Cache
import { Cache } from '@ebenezerdon/ts-node-cache'
const cache = new Cache()Store Data
cache.put('myKey', 'myValue', 5000, () => console.log('Expired'))Retrieve Data
let value = cache.get('myKey')Delete Data
cache.del('myKey')Clear Cache
cache.clear()Enable Debugging
cache.debug(true)Methods
put(key: string, value: T, time?: number, timeoutCallback?: (key: string, value: T) => void): Tget(key: string): T | nulldel(key: string): booleanclear(): voidsize(): numberdebug(bool: boolean): voidhits(): numbermisses(): numberkeys(): string[]exportJson(): stringimportJson(jsonToImport: string, options?: { skipDuplicates?: boolean }): number
Contributing
To contribute:
- Fork & Clone: Fork the repo and clone it locally.
- Make Changes: Work on your changes.
- Build: Run
npm run buildto build the project. - Test: Ensure your changes don't break anything.
- Submit a PR: Push your changes and submit a pull request.
License
This project is licensed under the ISC License - see the LICENSE file for details.