项目作者: jlopezxs

项目描述 :
:package: Simple memory cache decorator
高级语言: JavaScript
项目地址: git://github.com/jlopezxs/memory-cache-decorator.git
创建时间: 2017-01-17T11:34:05Z
项目社区:https://github.com/jlopezxs/memory-cache-decorator

开源协议:

下载


memory-cache-decorator

:package: Memory cache decorator

Requirements and Use

  1. npm install memory-cache-decorator --save

Use

  1. import cache from 'memory-cache-decorator';
  2. class Foo {
  3. constructor() {}
  4. @cache({ ttl: 2000 })
  5. getRandomNumber() {
  6. return Math.random();
  7. }
  8. }
  9. const bar = new Foo();
  10. bar.getRandomNumber(); //Returns 0.8625773520208384
  11. bar.getRandomNumber(); //Returns 0.8625773520208384
  12. setTimeout(()=> bar.getRandomNumber(), 2000) //Returns 0.7496571644076617