feather-cache
Advanced tools
Comparing version 1.2.1 to 1.3.1
@@ -28,3 +28,10 @@ import { IFeatherCacheDriver } from './feather-cache-driver.interface'; | ||
*/ | ||
fetch(key: string): Promise<{ | ||
fetch(key: string, options?: { | ||
/** | ||
* Deletes the record after expiry get. | ||
* default is `true`. | ||
* If you need to hold the delete, unset this option. | ||
*/ | ||
delete: boolean; | ||
}): Promise<{ | ||
validTill: Date; | ||
@@ -31,0 +38,0 @@ key: string; |
@@ -62,3 +62,3 @@ "use strict"; | ||
*/ | ||
fetch(key) { | ||
fetch(key, options = { delete: true }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -71,3 +71,5 @@ const data = yield this.options.getFn.call(this, key); | ||
// expired | ||
yield this.options.delFn.call(this, key); | ||
if (options.delete) { | ||
yield this.options.delFn.call(this, key); | ||
} | ||
data.__$EXPIRED = true; | ||
@@ -74,0 +76,0 @@ } |
{ | ||
"name": "feather-cache", | ||
"version": "1.2.1", | ||
"version": "1.3.1", | ||
"description": "A Simple Lightweight Pluggable Key-Value Cache For Multiple Storage Options.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/vajahath/feather-cache#readme", |
@@ -63,8 +63,8 @@ # feather-cache | ||
| function | description | | ||
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `FeatherCache.set(key, val, opt)` | returns `Promise`.<br>**`key`**: string<br>**`val`**: any data to be stored <br>**`opt`**: (optional) `{ maxAgeInMs: 1000 }`, sets expiry time. | | ||
| `FeatherCache.get(key)` | returns `Promise` which resolves to the stored data. else, `null`. <br> If data has expired returns `null` and then deletes the entry behind the scenes. | | ||
| `FeatherCache.fetch(key)` | returns `Promise` which resolves to stored data. The difference between `get` and `fetch` is that, `fetch` returns the stored data one more time after its expiry and then deletes it.<br>**More info:**<br>`get`: `finds data -> if expired deletes it -> returns null`.<br>`fetch`: `finds data -> if expired returns it -> and then deletes it`. | | ||
| `FeatherCache.del(key)` | returns `Promise` deletes the entry | | ||
| function | description | | ||
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `FeatherCache.set(key, val, opt)` | returns `Promise`.<br>**`key`**: string<br>**`val`**: any data to be stored <br>**`opt`**: (optional) `{ maxAgeInMs: 1000 }`, sets expiry time. | | ||
| `FeatherCache.get(key)` | returns `Promise` which resolves to the stored data. else, `null`. <br> If data has expired returns `null` and then deletes the entry behind the scenes. | | ||
| `FeatherCache.fetch(key)` | returns `Promise` which resolves to stored data. The difference between `get` and `fetch` is that, `fetch` returns the stored data one more time after its expiry and then deletes it.<br>**More info:**<br>`get`: `finds data -> if expired deletes it -> returns null`.<br>`fetch`: `finds data -> if expired returns it -> and then deletes it`.<br> However, you can control this behavior by passing the `delete` option (default `delete: true`). Eg: `fStore.fetch('hiya', { delete: false })`. This sets the expiry flag but don't delete it. Sometimes you may find this helpful. | | ||
| `FeatherCache.del(key)` | returns `Promise` deletes the entry | | ||
@@ -71,0 +71,0 @@ ## Configuration / writing drivers |
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
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
17665
219