Comparing version 2.4.2 to 2.5.0
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;class Cachu{constructor(t){this.set=async(t,s)=>{if(-1!==this.store.findIndex((s=>s[0]===t)))return!1;if(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf())),this.store.length===this.maxAmount){const t=this.store.reduce(((t,s)=>t[2]<s[2]?t:s));this.store.splice(this.store.findIndex((s=>s[0]===t[0])),1)}return this.store.push([t,s,Date.now()]),!0},this.get=async t=>{this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()));const s=this.store.findIndex((s=>s[0]===t));if(-1===s)return null;return this.store[s][1]},this.view=async t=>{this.store=this.store.filter((s=>Date.now()-s[2]<1e3*this.maxAge.valueOf()||s[0]===t));const s=this.store.findIndex((s=>s[0]===t));if(-1===s)return null;return this.store[s][1]},this.update=async(t,s)=>{const e=this.store.findIndex((s=>s[0]===t));return-1!==e&&(this.store[e]=[t,s,Date.now()],!0)},this.has=async t=>-1!==this.store.findIndex((s=>s[0]===t)),this.purge=async t=>{const s=this.store.findIndex((s=>s[0]===t));return-1!==s&&(this.store.splice(s,1),!0)},this.prune=async()=>(this.store.length>0&&(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()))),!0),this.destroy=async()=>(this.store=[],!0),this.purgeMany=async t=>{for(const s of t)await this.purge(s);return!0},this.getMany=async t=>{const s=[];for(const e of t){const t=await this.get(e);null===t&&void 0===t||s.push(t)}return s},this.purgeManyByCondition=async t=>(this.store=this.store.filter((s=>!t(s[0],s[1],s[2]))),!0),this.getManyByCondition=async t=>{const s=this.store.filter((s=>t(s[0],s[1],s[2]))),e=[];for(const t of s)e.push(t[1]);return e},this.getAmountOfItems=async()=>this.store.length,this.getValuesOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[1]))},this.getKeysOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[0]))},this.each=async t=>(this.store.forEach((async s=>{await t(s)})),!0),t||(t={}),this.maxAmount=t.maxAmount??1/0,this.maxAge=t.maxAge??1/0,this.store=[]}}exports.Cachu=Cachu; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;class Cachu{constructor(t){this.set=async(t,s)=>{if(-1!==this.store.findIndex((s=>s[0]===t)))return!1;if(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf())),this.store.length===this.maxAmount){const t=this.store.reduce(((t,s)=>t[2]<s[2]?t:s));this.store.splice(this.store.findIndex((s=>s[0]===t[0])),1)}return this.store.push([t,s,Date.now()]),!0},this.get=async t=>{this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()));const s=this.store.findIndex((s=>s[0]===t));if(-1===s)return null;return this.store[s][1]},this.view=async t=>{this.store=this.store.filter((s=>Date.now()-s[2]<1e3*this.maxAge.valueOf()||s[0]===t));const s=this.store.findIndex((s=>s[0]===t));if(-1===s)return null;return this.store[s][1]},this.update=async(t,s)=>{const e=this.store.findIndex((s=>s[0]===t));return-1!==e&&(this.store[e]=[t,s,Date.now()],!0)},this.has=async t=>-1!==this.store.findIndex((s=>s[0]===t)),this.purge=async t=>{const s=this.store.findIndex((s=>s[0]===t));return-1!==s&&(this.store.splice(s,1),!0)},this.prune=async()=>(this.store.length>0&&(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()))),!0),this.destroy=async()=>(this.store=[],!0),this.purgeMany=async t=>{for(const s of t)await this.purge(s);return!0},this.getMany=async t=>{const s=[];for(const e of t){const t=await this.get(e);null===t&&void 0===t||s.push(t)}return s},this.purgeManyByCondition=async t=>(this.store=this.store.filter((s=>!t(s[0],s[1],s[2]))),!0),this.getManyByCondition=async t=>{const s=this.store.filter((s=>t(s[0],s[1],s[2]))),e=[];for(const t of s)e.push(t[1]);return e},this.getAmountOfItems=async()=>this.store.length,this.getValuesOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[1]))},this.getKeysOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[0]))},this.each=async t=>(this.store.forEach((async s=>{await t(s)})),!0),this.steal=async t=>{this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()));const s=this.store.findIndex((s=>s[0]===t));if(-1===s)return null;const e=this.store[s];return this.store.splice(s,1),e[1]},this.stealMany=async t=>{const s=[];for(const e of t)s.push(await this.get(e)),await this.purge(e);return s},t||(t={}),this.maxAmount=t.maxAmount??1/0,this.maxAge=t.maxAge??1/0,this.store=[]}}exports.Cachu=Cachu; |
{ | ||
"name": "cachu", | ||
"version": "2.4.2", | ||
"version": "2.5.0", | ||
"description": "Simple, Minimalistic KV Cache", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -5,3 +5,2 @@ # cachu | ||
[![npm](https://img.shields.io/npm/dt/cachu)](https://www.npmjs.com/package/cachu) | ||
[![npm bundle size](https://img.shields.io/bundlephobia/min/cachu)](https://bundlephobia.com/package/cachu) | ||
[![GitHub last commit](https://img.shields.io/github/last-commit/azurystudios/cachu)](https://github.com/azurystudios/cachu) | ||
@@ -8,0 +7,0 @@ [![GitHub issues](https://img.shields.io/github/issues-raw/azurystudios/cachu)](https://github.com/azurystudios/cachu/issues) |
@@ -125,3 +125,17 @@ interface Configuration { | ||
each: (action: Function) => Promise<boolean>; | ||
/** | ||
* **Steal Item** | ||
* | ||
* Steal a item from the cache. | ||
* @param key | ||
*/ | ||
steal: (key: {}) => Promise<any>; | ||
/** | ||
* **Steal Many Items** | ||
* | ||
* Steal many items from the cache. | ||
* @param keys | ||
*/ | ||
stealMany: (keys: Array<any>) => Promise<any[]>; | ||
} | ||
export {}; |
22029
140
81