Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ritikesh/memoize_until
A unique Memoization Pattern, rewritten in typescript. Original at https://github.com/freshworks/memoize_until
https://github.com/ritikesh/memoize_until
cachemanager javascript memoization ttl-cache-implementation typescript
Last synced: 27 days ago
JSON representation
A unique Memoization Pattern, rewritten in typescript. Original at https://github.com/freshworks/memoize_until
- Host: GitHub
- URL: https://github.com/ritikesh/memoize_until
- Owner: ritikesh
- License: mit
- Created: 2019-03-05T20:24:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-19T14:16:07.000Z (about 1 year ago)
- Last Synced: 2024-10-04T05:20:58.060Z (about 1 month ago)
- Topics: cachemanager, javascript, memoization, ttl-cache-implementation, typescript
- Language: TypeScript
- Homepage:
- Size: 951 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MemoizeUntil
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/ritikesh/memoize_until/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/ritikesh/memoize_until/tree/master)
![Version](https://img.shields.io/npm/v/memoize_until.svg)
![Downlaods](https://img.shields.io/npm/dt/memoize_until.svg)A unique Memoization Pattern which memoizes until the next time metric - could be until the next minute, hour, day, week.
## Get Started
Install `memoize_until` with:
```bash
npm install memoize_until --save-dev
```## Usage
```javascript
const MemoizeUntil = require('memoize_until').MemoizeUntilMemoizeUntil.fetch('min', 'default', () => {
return 'SomeComplexOperation';
})
```#### options:
1. `min` : Metric until when you want to memoize. Can be one of ['min', 'hour', 'day', 'week']2. `default` : All metric levels come with a 'default' key. More can be added by [initializing](#Initialisation) `MemoizeUntil` with extra keys
3. `cb`: callback function. This callback function must return a value which needs to be memoized/cached.
## Initialisation
To add custom keys to each metric, pass a custom object to the `init` function of `MemoizeUntil`.
```javascript
MemoizeUntil.init({
min: ['custom1', 'custom2']
})MemoizeUntil.fetch('min', 'custom1', () => {
return 'SomeComplexOperation';
})
```## Extend
To add custom keys during runtime to any metric, use the `extend` function of `MemoizeUntil`.
```javascript
let runtime_key = 'runtime_key';
MemoizeUntil.extend('min', runtime_key)MemoizeUntil.fetch('min', runtime_key, () => {
return 'SomeComplexOperation';
})
```## Nulls
if the value to be memoized is `undefined` or `null`, `MemoizeUntil` wraps it underneath a pseudo null-like object called `NullObject` and always returns `undefined`. This ensures that even nulls are memoized.## License
[Ritikesh](https://ritikesh.github.io)
Licensed under the MIT license.