1.1.2 • Published 9 years ago

yield-cache v1.1.2

Weekly downloads
5
License
ISC
Repository
github
Last release
9 years ago

yield-cache

Build Status Coverage Status

Cache utility for generator

plover \ node5.x4.x0.12.x
0.x.x
1.x.xX
$ npm install yield-cache

API

yieldCache()

create cache instance

var cache = yieldCache();

cache(key, obj)

try get item from cache or yeild from obj

cache.remove(key)

remove cache item for key

Useage

1. Create an instance for cache a group of generator

var cache = yieldCache();

2. Use cache instance

// it should used in generator function
function* () {
  // call with cackeKey and yieldable object
  var item = yield* cache(cacheKey, Generator or GeneratorFunction or Functin that return Promise);
}

Example

var yieldCache = require('yield-cache');


// create an instance
var renderCache = yieldCache();


// use
function* getRender(path) {
  var render = yield* renderCache(path, function* () {
    var tpl = yield fs.readFile(path, 'utf-8');
    return compiler.complie(tpl);
  });

  return render;
}


var path = ...
var render = yield* getRender(path);
var render2 = yield* getRender(path);

render.should.equal(render2);
1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago