+14
| declare interface Options { | ||
| max?: number; | ||
| maxAge?: number; | ||
| stale?: boolean; | ||
| } | ||
| declare class Cache<K, V> extends Map<K, V> { | ||
| constructor(options?: Options | number); | ||
| get(key: K, refresh?: boolean): V | undefined; | ||
| peek(key: K): V | undefined; | ||
| set(key: K, value: V, maxAge?: number): this; | ||
| } | ||
| export = Cache; |
+1
-2
@@ -19,5 +19,4 @@ class Cache extends Map { | ||
| set(key, content, maxAge) { | ||
| set(key, content, maxAge = this.maxAge) { | ||
| this.has(key) && this.delete(key); | ||
| maxAge = maxAge !== void 0 ? maxAge : this.maxAge; | ||
| (this.size + 1 > this.max) && this.delete(this.keys().next().value); | ||
@@ -24,0 +23,0 @@ let expires = maxAge > -1 && (maxAge + Date.now()); |
+7
-6
| { | ||
| "name": "tmp-cache", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "repository": "lukeed/tmp-cache", | ||
| "description": "A least-recently-used cache manager in 35 lines of code", | ||
| "description": "A least-recently-used cache in 35 lines of code", | ||
| "main": "lib/index.js", | ||
| "types": "index.d.ts", | ||
| "license": "MIT", | ||
@@ -11,3 +12,3 @@ "author": { | ||
| "email": "luke.edwards05@gmail.com", | ||
| "url": "lukeed.com" | ||
| "url": "https://lukeed.com" | ||
| }, | ||
@@ -18,5 +19,6 @@ "engines": { | ||
| "scripts": { | ||
| "test": "tape test/*.js | tap-spec" | ||
| "test": "uvu test" | ||
| }, | ||
| "files": [ | ||
| "*.d.ts", | ||
| "lib" | ||
@@ -31,5 +33,4 @@ ], | ||
| "devDependencies": { | ||
| "tap-spec": "^4.1.1", | ||
| "tape": "^4.8.0" | ||
| "uvu": "0.3.3" | ||
| } | ||
| } |
+2
-2
@@ -1,4 +0,4 @@ | ||
| # tmp-cache [](https://travis-ci.org/lukeed/tmp-cache) | ||
| # tmp-cache  [](https://codecov.io/gh/lukeed/tmp-cache) | ||
| > A least-recently-used cache manager in 35 lines of code~! | ||
| > A least-recently-used cache in 35 lines of code~! | ||
@@ -5,0 +5,0 @@ LRU caches operate on a first-in-first-out queue. This means that the first item is the oldest and will therefore be deleted once the `max` limit has been reached. |
7256
4.58%1
-50%5
25%45
32.35%