https://github.com/littlstar/expiration
Cache list (It is a list you can add items to, find out the length and retrieve the list... but the items expire some amount of time after being added)
https://github.com/littlstar/expiration
Last synced: over 1 year ago
JSON representation
Cache list (It is a list you can add items to, find out the length and retrieve the list... but the items expire some amount of time after being added)
- Host: GitHub
- URL: https://github.com/littlstar/expiration
- Owner: littlstar
- License: mit
- Created: 2018-02-01T19:04:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-07T16:49:53.000Z (over 8 years ago)
- Last Synced: 2025-02-24T11:46:40.696Z (almost 2 years ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
## Expiration
For having an array of items that expire after a dynamic amount of time
### Install:
```bash
npm install expiration
```
### Quick Example:
```javascript
const ExpireList = require('expiration')
const expireList = new ExpireList()
// Expire in 10s
expireList.add('hey!', 10000)
// Expire in 60s
expireList.add('bye!')
console.log(expireList.length) // 2
console.log(expireList.list) // [ 'hey!', 'bye!']
...
// 30s later
console.log(expireList.length) // 1
console.log(expireList.list) // [ 'bye!' ]
...
// 60s later
console.log(expireList.length) // 0
console.log(expireList.list) // []
```
## Methods
### constructor()
Creates a new expiring list
### add(storeItem, timeToCache = 60000)
Adds the given item to the list and removes from the list in the given amount of milliseconds
#### Parameters:
- `storeItem` - Object to store (can be a string, number, item, whatever)
- `timeToCache` - Amount of milliseconds to store
### length
How long is the list
### list
What is the list at the given time
## Notes:
Full example can be found under [`test/`](test).