https://github.com/z3ut/tlru-cache
Time aware least recently used cache storage
https://github.com/z3ut/tlru-cache
Last synced: 7 days ago
JSON representation
Time aware least recently used cache storage
- Host: GitHub
- URL: https://github.com/z3ut/tlru-cache
- Owner: z3ut
- Created: 2018-10-07T18:18:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T18:18:42.000Z (over 7 years ago)
- Last Synced: 2025-01-13T22:28:27.018Z (over 1 year ago)
- Language: TypeScript
- Size: 44.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
TLRU-Cache
=
Time aware least recently used cache store
## Installation
```
npm i tlru-cache
```
## Usage
```typescript
import { TLRUCache } from 'tlru-cache';
const tlruCache = new TLRUCache({
// optional values
maxStoreSize: 5,
timeToUseMs: 60 * 1000,
});
const value = tlruCache.get('value', () => 42);
// won't calculate again
const sameValue = tlruCache.get('value', () => 42);
```
## Documentation
### Constructor object properties:
Name | Type | Default value | Description
---|---|---|---
maxStoreSize | number | 1000 | Store capacity
maxAgeMs | number | 60 * 60 * 1000 (1 hour) | Record time to use in milliseconds. Put <= 0 for non-expiring records.
### Methods:
```typescript
get(key: TKey, calculate: (key: TKey) => TValue, maxAgeMs: number = null): TValue
```
#### Arguments:
* **key**: record key
* **calculate**: function to get record. receive key as argument
* **maxAgeMs**: record time to use. if presented, override constructor option