alaska-cache-lru
Advanced tools
Comparing version 0.11.21 to 0.12.0
73
index.js
@@ -1,23 +0,30 @@ | ||
// @flow | ||
'use strict'; | ||
/* eslint new-cap:0 */ | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
import LRU from 'lru-cache'; | ||
import Debugger from 'debug'; | ||
import { Driver } from 'alaska'; | ||
var _lruCache = require('lru-cache'); | ||
const debug = Debugger('alaska-cache-lru'); | ||
var _lruCache2 = _interopRequireDefault(_lruCache); | ||
export default class LruCacheDriver extends Driver { | ||
static classOfCacheDriver = true; | ||
var _debug = require('debug'); | ||
instanceOfCacheDriver: true; | ||
_maxAge: number; | ||
_driver: any; | ||
var _debug2 = _interopRequireDefault(_debug); | ||
constructor(service: Alaska$Service, options: Object) { | ||
var _alaska = require('alaska'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const debug = (0, _debug2.default)('alaska-cache-lru'); | ||
/* eslint new-cap:0 */ | ||
class LruCacheDriver extends _alaska.Driver { | ||
constructor(service, options) { | ||
super(service, options); | ||
this.instanceOfCacheDriver = true; | ||
this._maxAge = options.maxAge || 0; | ||
this._driver = new LRU(options); | ||
this._driver = new _lruCache2.default(options); | ||
} | ||
@@ -29,3 +36,3 @@ | ||
*/ | ||
driver(): any { | ||
driver() { | ||
return this._driver; | ||
@@ -35,3 +42,3 @@ } | ||
/** | ||
* [async] 设置缓存 | ||
* 设置缓存 | ||
* @param {string} key | ||
@@ -42,3 +49,3 @@ * @param {*} value | ||
*/ | ||
set(key: string, value: any, lifetime?: number): Promise<any> { | ||
set(key, value, lifetime) { | ||
debug('set', key, '=>', value, '(', lifetime !== undefined ? lifetime : '{' + this._maxAge + '}', ')'); | ||
@@ -49,7 +56,7 @@ return Promise.resolve(this._driver.set(key, value, lifetime)); | ||
/** | ||
* [async] 获取缓存 | ||
* 获取缓存 | ||
* @param key | ||
* @returns {*} | ||
*/ | ||
get(key: string): Promise<any> { | ||
get(key) { | ||
let value = this._driver.get(key); | ||
@@ -61,6 +68,6 @@ debug('get', key, '=>', value); | ||
/** | ||
* [async] 删除缓存 | ||
* 删除缓存 | ||
* @param key | ||
*/ | ||
del(key: string): Promise<any> { | ||
del(key) { | ||
debug('del', key); | ||
@@ -71,7 +78,7 @@ return Promise.resolve(this._driver.del(key)); | ||
/** | ||
* [async] 判断缓存键是否存在 | ||
* 判断缓存键是否存在 | ||
* @param key | ||
* @returns {boolean} | ||
*/ | ||
has(key: string): Promise<boolean> { | ||
has(key) { | ||
let exists = this._driver.has(key); | ||
@@ -83,7 +90,7 @@ debug('has', key, '=>', exists); | ||
/** | ||
* [async] 自增并返回结果 | ||
* 自增并返回结果 | ||
* @param key | ||
* @returns {number} | ||
*/ | ||
inc(key: string): Promise<number> { | ||
inc(key) { | ||
let value = this._driver.get(key); | ||
@@ -100,7 +107,7 @@ if (!value) { | ||
/** | ||
* [async] 自减并返回结果 | ||
* 自减并返回结果 | ||
* @param key | ||
* @returns {number} | ||
*/ | ||
dec(key: string): Promise<number> { | ||
dec(key) { | ||
let value = this._driver.get(key); | ||
@@ -117,6 +124,6 @@ if (!value) { | ||
/** | ||
* [async] 返回缓存数量 | ||
* 返回缓存数量 | ||
* @returns {number} | ||
*/ | ||
size(): Promise<number> { | ||
size() { | ||
debug('size', this._driver.itemCount); | ||
@@ -127,5 +134,5 @@ return Promise.resolve(this._driver.itemCount); | ||
/** | ||
* [async] 清理过期缓存 | ||
* 清理过期缓存 | ||
*/ | ||
prune(): Promise<void> { | ||
prune() { | ||
debug('prune'); | ||
@@ -137,5 +144,5 @@ this._driver.prune(); | ||
/** | ||
* [async] 清空缓存 | ||
* 清空缓存 | ||
*/ | ||
flush(): Promise<void> { | ||
flush() { | ||
debug('flush'); | ||
@@ -151,1 +158,3 @@ this._driver.reset(); | ||
} | ||
exports.default = LruCacheDriver; | ||
LruCacheDriver.classOfCacheDriver = true; |
{ | ||
"name": "alaska-cache-lru", | ||
"version": "0.11.21", | ||
"version": "0.12.0", | ||
"description": "Alaska LRU cache driver", | ||
@@ -9,10 +9,12 @@ "keywords": [ | ||
], | ||
"alaska": "driver", | ||
"alaska-driver": "cache", | ||
"main": "index.js", | ||
"repository": "https://github.com/maichong/alaska/tree/master/packages/alaska-cache-lru", | ||
"repository": "https://github.com/maichong/alaska/tree/master/src/alaska-cache-lru", | ||
"author": "Liang <liang@maichong.it> (https://github.com/liangxingchen)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"debug": "^2.6.8", | ||
"debug": "^3.1.0", | ||
"lru-cache": "^4.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4019
125
+ Addeddebug@3.2.7(transitive)
+ Addedms@2.1.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)
Updateddebug@^3.1.0