Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dwelle/toad-cache

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dwelle/toad-cache - npm Package Compare versions

Comparing version 3.3.1 to 3.3.2

2

dist/@dwelle/toad-cache.js

@@ -6,3 +6,3 @@ /**

* @license MIT
* @version 3.3.1
* @version 3.3.2
*/

@@ -9,0 +9,0 @@ class FifoMap {

/*!
2023 Igor Savin <kibertoad@gmail.com>
@version 3.3.1
@version 3.3.2
*/
class t{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=new Map,this.last=null,this.max=t,this.ttl=s}get size(){return this.items.size}clear(){this.items=new Map,this.first=null,this.last=null}delete(t){if(this.items.has(t)){const s=this.items.get(t);this.items.delete(t),null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(this.items.has(t))return this.items.get(t).expiry}get(t){if(this.items.has(t)){const s=this.items.get(t);return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):s.value}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return this.items.keys()}set(t,s){if(this.items.has(t)){const i=this.items.get(t);return i.value=s,void(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl)}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items.set(t,i),1===this.size?this.first=i:this.last.next=i,this.last=i}}class s{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=new Map,this.last=null,this.max=t,this.ttl=s}get size(){return this.items.size}bumpLru(t){if(this.last===t)return;const s=this.last,i=t.next,e=t.prev;this.first===t&&(this.first=t.next),t.next=null,t.prev=this.last,s.next=t,null!==e&&(e.next=i),null!==i&&(i.prev=e),this.last=t}clear(){this.items=new Map,this.first=null,this.last=null}delete(t){if(this.items.has(t)){const s=this.items.get(t);this.items.delete(t),null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(this.items.has(t))return this.items.get(t).expiry}get(t){if(this.items.has(t)){const s=this.items.get(t);return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):(this.bumpLru(s),s.value)}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return this.items.keys()}set(t,s){if(this.items.has(t)){const i=this.items.get(t);return i.value=s,i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl,void(this.last!==i&&this.bumpLru(i))}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items.set(t,i),1===this.size?this.first=i:this.last.next=i,this.last=i}}class i{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this.max=t,this.ttl=s}bumpLru(t){if(this.last===t)return;const s=this.last,i=t.next,e=t.prev;this.first===t&&(this.first=t.next),t.next=null,t.prev=this.last,s.next=t,null!==e&&(e.next=i),null!==i&&(i.prev=e),this.last=t}clear(){this.items=Object.create(null),this.first=null,this.last=null,this.size=0}delete(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(Object.prototype.hasOwnProperty.call(this.items,t))return this.items[t].expiry}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):(this.bumpLru(s),s.value)}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return Object.keys(this.items)}set(t,s){if(Object.prototype.hasOwnProperty.call(this.items,t)){const i=this.items[t];return i.value=s,i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl,void(this.last!==i&&this.bumpLru(i))}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items[t]=i,1==++this.size?this.first=i:this.last.next=i,this.last=i}}class e{constructor(){this.records={}}initForCache(t,s){this.records[t]={[s]:{hits:0,misses:0,expirations:0}}}resetForCache(t){for(let s of Object.keys(this.records[t]))this.records[t][s]={hits:0,misses:0,expirations:0}}getStatistics(){return this.records}}function r(t){return`${t.getFullYear()}-${(t.getMonth()+1).toString().padStart(2,"0")}-${t.getDate().toString().padStart(2,"0")}`}class h{constructor(t,s,i){this.collectionStart=new Date,this.lastTimeStamp="",this.currentTimeStamp=r(this.collectionStart),this.cacheId=t,this.statisticTtlInHours=s,this.records=i||new e,this.records.initForCache(this.cacheId,this.currentTimeStamp)}hoursPassed(){return(Date.now()-this.collectionStart)/1e3/60/60}addHit(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].hits++}addMiss(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].misses++}addExpiration(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].expirations++}getStatistics(){return this.records.getStatistics()}archiveIfNeeded(){if(this.hoursPassed()>=this.statisticTtlInHours){const t=new Date,s=r(t);this.lastTimeStamp&&this.lastTimeStamp!==s&&delete this.records.records[this.cacheId][this.lastTimeStamp],this.lastTimeStamp=this.currentTimeStamp,this.collectionStart=t,this.currentTimeStamp=r(this.collectionStart),this.records.initForCache(this.cacheId,this.currentTimeStamp)}}}class l extends i{constructor(t,s,i,e,r){if(super(t||1e3,s||0),!i)throw new Error("Cache id is mandatory");this.hitStatistics=new h(i,void 0!==r?r:24,e)}getStatistics(){return this.hitStatistics.getStatistics()}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?(this.delete(t),void this.hitStatistics.addExpiration()):(this.bumpLru(s),this.hitStatistics.addHit(),s.value)}this.hitStatistics.addMiss()}}class n{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this.max=t,this.ttl=s}clear(){this.items=Object.create(null),this.first=null,this.last=null,this.size=0}delete(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(Object.prototype.hasOwnProperty.call(this.items,t))return this.items[t].expiry}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):s.value}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return Object.keys(this.items)}set(t,s){if(Object.prototype.hasOwnProperty.call(this.items,t)){const i=this.items[t];return i.value=s,void(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl)}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items[t]=i,1==++this.size?this.first=i:this.last.next=i,this.last=i}}export{n as Fifo,t as FifoMap,n as FifoObject,e as HitStatisticsRecord,i as Lru,l as LruHitStatistics,s as LruMap,i as LruObject,l as LruObjectHitStatistics};//# sourceMappingURL=toad-cache.min.js.map

@@ -6,3 +6,3 @@ /**

* @license MIT
* @version 3.3.1
* @version 3.3.2
*/

@@ -9,0 +9,0 @@ (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g["toad-cache"]={}));})(this,(function(exports){'use strict';class FifoMap {

/*!
2023 Igor Savin <kibertoad@gmail.com>
@version 3.3.1
@version 3.3.2
*/
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self)["toad-cache"]={})}(this,(function(t){"use strict";class s{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this.max=t,this.ttl=s}bumpLru(t){if(this.last===t)return;const s=this.last,i=t.next,e=t.prev;this.first===t&&(this.first=t.next),t.next=null,t.prev=this.last,s.next=t,null!==e&&(e.next=i),null!==i&&(i.prev=e),this.last=t}clear(){this.items=Object.create(null),this.first=null,this.last=null,this.size=0}delete(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(Object.prototype.hasOwnProperty.call(this.items,t))return this.items[t].expiry}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):(this.bumpLru(s),s.value)}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return Object.keys(this.items)}set(t,s){if(Object.prototype.hasOwnProperty.call(this.items,t)){const i=this.items[t];return i.value=s,i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl,void(this.last!==i&&this.bumpLru(i))}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items[t]=i,1==++this.size?this.first=i:this.last.next=i,this.last=i}}class i{constructor(){this.records={}}initForCache(t,s){this.records[t]={[s]:{hits:0,misses:0,expirations:0}}}resetForCache(t){for(let s of Object.keys(this.records[t]))this.records[t][s]={hits:0,misses:0,expirations:0}}getStatistics(){return this.records}}function e(t){return`${t.getFullYear()}-${(t.getMonth()+1).toString().padStart(2,"0")}-${t.getDate().toString().padStart(2,"0")}`}class r{constructor(t,s,r){this.collectionStart=new Date,this.lastTimeStamp="",this.currentTimeStamp=e(this.collectionStart),this.cacheId=t,this.statisticTtlInHours=s,this.records=r||new i,this.records.initForCache(this.cacheId,this.currentTimeStamp)}hoursPassed(){return(Date.now()-this.collectionStart)/1e3/60/60}addHit(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].hits++}addMiss(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].misses++}addExpiration(){this.archiveIfNeeded(),this.records.records[this.cacheId][this.currentTimeStamp].expirations++}getStatistics(){return this.records.getStatistics()}archiveIfNeeded(){if(this.hoursPassed()>=this.statisticTtlInHours){const t=new Date,s=e(t);this.lastTimeStamp&&this.lastTimeStamp!==s&&delete this.records.records[this.cacheId][this.lastTimeStamp],this.lastTimeStamp=this.currentTimeStamp,this.collectionStart=t,this.currentTimeStamp=e(this.collectionStart),this.records.initForCache(this.cacheId,this.currentTimeStamp)}}}class h extends s{constructor(t,s,i,e,h){if(super(t||1e3,s||0),!i)throw new Error("Cache id is mandatory");this.hitStatistics=new r(i,void 0!==h?h:24,e)}getStatistics(){return this.hitStatistics.getStatistics()}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?(this.delete(t),void this.hitStatistics.addExpiration()):(this.bumpLru(s),this.hitStatistics.addHit(),s.value)}this.hitStatistics.addMiss()}}class l{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this.max=t,this.ttl=s}clear(){this.items=Object.create(null),this.first=null,this.last=null,this.size=0}delete(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(Object.prototype.hasOwnProperty.call(this.items,t))return this.items[t].expiry}get(t){if(Object.prototype.hasOwnProperty.call(this.items,t)){const s=this.items[t];return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):s.value}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return Object.keys(this.items)}set(t,s){if(Object.prototype.hasOwnProperty.call(this.items,t)){const i=this.items[t];return i.value=s,void(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl)}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items[t]=i,1==++this.size?this.first=i:this.last.next=i,this.last=i}}t.Fifo=l,t.FifoMap=class{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=new Map,this.last=null,this.max=t,this.ttl=s}get size(){return this.items.size}clear(){this.items=new Map,this.first=null,this.last=null}delete(t){if(this.items.has(t)){const s=this.items.get(t);this.items.delete(t),null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(this.items.has(t))return this.items.get(t).expiry}get(t){if(this.items.has(t)){const s=this.items.get(t);return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):s.value}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return this.items.keys()}set(t,s){if(this.items.has(t)){const i=this.items.get(t);return i.value=s,void(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl)}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items.set(t,i),1===this.size?this.first=i:this.last.next=i,this.last=i}},t.FifoObject=l,t.HitStatisticsRecord=i,t.Lru=s,t.LruHitStatistics=h,t.LruMap=class{constructor(t=1e3,s=0){if(isNaN(t)||t<0)throw new Error("Invalid max value");if(isNaN(s)||s<0)throw new Error("Invalid ttl value");this.first=null,this.items=new Map,this.last=null,this.max=t,this.ttl=s}get size(){return this.items.size}bumpLru(t){if(this.last===t)return;const s=this.last,i=t.next,e=t.prev;this.first===t&&(this.first=t.next),t.next=null,t.prev=this.last,s.next=t,null!==e&&(e.next=i),null!==i&&(i.prev=e),this.last=t}clear(){this.items=new Map,this.first=null,this.last=null}delete(t){if(this.items.has(t)){const s=this.items.get(t);this.items.delete(t),null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}}deleteMany(t){for(var s=0;s<t.length;s++)this.delete(t[s])}evict(){if(this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}}expiresAt(t){if(this.items.has(t))return this.items.get(t).expiry}get(t){if(this.items.has(t)){const s=this.items.get(t);return this.ttl>0&&s.expiry<=Date.now()?void this.delete(t):(this.bumpLru(s),s.value)}}getMany(t){const s=[];for(var i=0;i<t.length;i++)s.push(this.get(t[i]));return s}keys(){return this.items.keys()}set(t,s){if(this.items.has(t)){const i=this.items.get(t);return i.value=s,i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl,void(this.last!==i&&this.bumpLru(i))}this.max>0&&this.size===this.max&&this.evict();const i={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s};this.items.set(t,i),1===this.size?this.first=i:this.last.next=i,this.last=i}},t.LruObject=s,t.LruObjectHitStatistics=h}));//# sourceMappingURL=toad-cache.umd.min.js.map
{
"name": "@dwelle/toad-cache",
"description": "LRU and FIFO caches for Client or Server",
"version": "3.3.1",
"version": "3.3.2",
"homepage": "https://github.com/kibertoad/toad-cache",

@@ -20,3 +20,3 @@ "author": "Igor Savin <kibertoad@gmail.com>",

"source": "index.js",
"main": "dist/toad-cache",
"main": "dist/@dwelle/toad-cache",
"exports": {

@@ -23,0 +23,0 @@ "types": "./toad-cache.d.ts",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc