https://github.com/ebenezerdon/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.
https://github.com/ebenezerdon/ts-node-cache
cache cache-storage caching node typscript
Last synced: 22 days ago
JSON representation
TS-Node-Cache is a TypeScript-based caching solution that's simple and lightweight. It supports data caching with optional expiration and callbacks.
- Host: GitHub
- URL: https://github.com/ebenezerdon/ts-node-cache
- Owner: ebenezerdon
- License: isc
- Created: 2024-04-09T10:19:36.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T17:13:53.000Z (about 2 years ago)
- Last Synced: 2025-10-13T14:55:31.024Z (7 months ago)
- Topics: cache, cache-storage, caching, node, typscript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@ebenezerdon/ts-node-cache
- Size: 52.7 KB
- Stars: 16
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://www.npmjs.com/package/memory-cache) but with modern implementation and TypeScript support.
[](https://badge.fury.io/js/%40ebenezerdon%2Fts-node-cache)
[](https://opensource.org/licenses/ISC)
## 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
```bash
npm install @ebenezerdon/ts-node-cache
```
## Usage
### Import and Create Cache
```typescript
import { Cache } from '@ebenezerdon/ts-node-cache'
const cache = new Cache()
```
### Store Data
```typescript
cache.put('myKey', 'myValue', 5000, () => console.log('Expired'))
```
### Retrieve Data
```typescript
let value = cache.get('myKey')
```
### Delete Data
```typescript
cache.del('myKey')
```
### Clear Cache
```typescript
cache.clear()
```
### Enable Debugging
```typescript
cache.debug(true)
```
## Methods
- `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`
## Contributing
To contribute:
1. **Fork & Clone**: Fork the repo and clone it locally.
2. **Make Changes**: Work on your changes.
3. **Build**: Run `npm run build` to build the project.
4. **Test**: Ensure your changes don't break anything.
5. **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.