项目作者: qalfaki

项目描述 :
distributed LRU cache
高级语言: JavaScript
项目地址: git://github.com/qalfaki/lru-cache.git
创建时间: 2019-10-29T16:04:17Z
项目社区:https://github.com/qalfaki/lru-cache

开源协议:

下载


distributed lur caching

Supported Feaures

  1. distributed cache
  2. real-time read/write
  3. cache expires

Geo-distributed-lru-cache-1.png

Project Status

beta!
  • PRs and Ideas are highly welcomed!

usage

  1. const Cache = require('disributed-lru-cache');
  2. //distributed lru cache uses rabbitmq for sync cache across different instances
  3. let cache = new Cache(brokerURL); // cache instance
  4. //sets a value in cache with 'a' as key and 1 as value
  5. cache.set('a', 1);
  6. cache.set('b', 2);
  7. cache.set('c', 3);
  8. /*
  9. [ { key: 'a', value: 1 },
  10. { key: 'b', value: 2 },
  11. { key: 'c', value: 3 } ]
  12. */
  13. cache.get('c') //returns 3 and makes it most recently used
  14. /*
  15. [ { key: 'c', value: 3 },
  16. [ { key: 'a', value: 1 },
  17. { key: 'b', value: 2 } ]
  18. */
  19. cache.peek('a') //returns 1 but doesnt resets the order
  20. /*
  21. [ { key: 'c', value: 3 },
  22. { key: 'a', value: 1 },
  23. { key: 'b', value: 2 } ]
  24. */
  25. cache.has('z') // returns boolean
  26. //Initialize Cache that expires in 3 hours
  27. let cache = new Cache(brokerURL, 3);

API

cache(brokerURL, expireIn[hours])

brokerURL

Type: ‘string’

rabbitmq broker url

expireIn

Type: number

default: Infinity