https://github.com/jsnomad/cache-lite
Node in-memory caching system
https://github.com/jsnomad/cache-lite
cache lite nodejs
Last synced: about 2 months ago
JSON representation
Node in-memory caching system
- Host: GitHub
- URL: https://github.com/jsnomad/cache-lite
- Owner: jsnomad
- License: mit
- Created: 2016-05-27T18:19:05.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-26T19:29:18.000Z (almost 10 years ago)
- Last Synced: 2025-03-11T11:51:38.392Z (over 1 year ago)
- Topics: cache, lite, nodejs
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/cache-lite)
# cache-lite [](https://circleci.com/gh/jsnomad/cache-lite)
## Description
Simple node in-memory caching system
## Download
The source is available for download from
[GitHub](https://github.com/jsnomad/cache-lite).
Alternatively, you can install using Node Package Manager (npm):
npm install cache-lite
## Example
```js
const CacheLite = require('cache-lite');
const cache = new CacheLite()
// Set value in the cache for 200ms
cache.set("myKey", "myData", 200).then(() => {
})
// Get value from the cache
cache.get("myKey").then((value) => {
console.log(value); // myData
})
cache.getKeys() // [ 'myKey' ]
cache.size() // 1
//Get value from the cache after 300ms
setTimeout(() => {
cache.get("myKey").then((value) => {
}).catch((err) => {
// Error: The key myKey doesn't exist in the cache
})
}, 300);
```
## API
###set(key, value, ttl)
Returns a promises
#### key
Type: `string`
Key
#### value
Type: `string`
Value
#### ttl (optional)
Type: `number`
Time to live
###get(key)
Returns a promises
#### key
Type: `string`
Key
###getKeys()
Returns keys stored in the cache
###size()
Returns the number of elements in the cache
###clear()
Delete all cached values from the cache
## Requirement
Node >= 5.0
## License
MIT © [Thomas Blanc-Hector](https://github.com/jsnomad)