Comparing version 0.2.5 to 0.2.6
@@ -13,10 +13,16 @@ // Global cache for constructor classes | ||
var fn = isValidFunc(cls.prototype[method], method) | ||
key = key || cached.DEFAULT_PROTO_KEY.replace('{_fn_}', fn[_REALNAME]) | ||
key = key || cached.DEFAULT_PROTO_KEY.replace('{_fn_}', method) | ||
hiddenProperty(fn, _REALNAME, fn.name || method) | ||
cls.addCacheKey(key) | ||
cls.prototype['fresh_' + method] = fn | ||
cls.prototype[method] = cached.wrap(fn, key, ttl, cls.prototype) | ||
cls.prototype[method] = cached.wrap(fn, key, ttl) | ||
} | ||
return function _enableCache(method, key, ttl) { | ||
var cls = this, fn | ||
// can pass ttl as the second argument | ||
if ('number' === typeof key) { | ||
ttl = key | ||
key = null | ||
} | ||
if (method[0] === '.') { | ||
@@ -26,3 +32,3 @@ return enableInstCache.call(this, method.slice(1), key, ttl) | ||
fn = isValidFunc(cls[method], method) | ||
key = key || cached.DEFAULT_KEY.replace('{_fn_}', fn[_REALNAME]) | ||
key = key || cached.DEFAULT_KEY.replace('{_fn_}', method) | ||
hiddenProperty(fn, _REALNAME, fn.name || method) | ||
@@ -29,0 +35,0 @@ cls['fresh_' + method] = fn |
{ | ||
"name": "cacheable", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "A cache wrapper with redis", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -178,2 +178,6 @@ # Cacheable | ||
User.enableCache('.getPostIds', 'posts-{0}-{1}') | ||
// You can omit the key, cacheable will automatically use the method name | ||
User.enableCache('.getPostIds', 3600) | ||
// KEY: '{_model_}:{id}:getTagsIds', expires in: 3600 seconds | ||
``` | ||
@@ -183,10 +187,5 @@ | ||
For an instance method, the default `key` would be: | ||
{_model_}:{this.id}:{_fn_} | ||
## License | ||
the MIT licence. |
13972
281
190