Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fatelei/simple-lru-cache
a simple cache using lru algthorim
https://github.com/fatelei/simple-lru-cache
Last synced: about 1 month ago
JSON representation
a simple cache using lru algthorim
- Host: GitHub
- URL: https://github.com/fatelei/simple-lru-cache
- Owner: fatelei
- Created: 2014-04-01T03:03:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T03:16:25.000Z (about 9 years ago)
- Last Synced: 2024-10-31T09:46:35.673Z (about 2 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Memory storage
==============![Build Status](https://travis-ci.org/fatelei/simple-lru-cache.svg)
A simple memory storage based [LRU](https://en.wikipedia.org/wiki/Cache_algorithms) algthorim.
## Install
```
npm install memory-storage
```## APIs
### LRUCache
Intialize a `LRUCache` instance.
+ size {Number}: cache size, default is 10
#### Usage
```
const LRUCache = require('memory-storage');
const cache = new LRUCache();
```or
```
const LRUCache = require('memory-storage');
const cache = new LRUCache(100);
```### set
Set to cache.
+ key {String}: key name
+ value {Any}: To be cached value#### Usage
```
cache.set('a', 1); // Set number
cache.set('a', {}); // Set object
cache.set('a', []); // Set array
cache.set('a', 'a'); // Set string
```### setex
Set to cache and add expire time(seconds).
+ key {String}: key name
+ value {Any}: to be cached value
+ expire {Number}: expire seconds#### Usage
```
cache.set('a', 1, 100);
```### expire
Expire key in seconds
+ key {String}: key name
+ expire {Number}: expire seconds#### Usage
```
cache.expire('a', 100);
```### get
Get value by key, return real value or undefined.
+ key {String}: key name
#### Usage
```
cache.get('foo');
```### rpush
Push `value` to named `key`'s array.
+ key {String}: key name
+ value {Any}: To be cached value#### Usage
```
cache.rpush('a', 'a');
```### rpop
Pop `value` from named `key`'s array and return it.
+ key {String}: key name
#### Usage
```
cache.rpush('a', 1);
console.log(cache.rpop('a'));
```## Test
```
jasmine
```## TODO
+ support more apis like redis command.