Socket
Socket
Sign inDemoInstall

runtime-memcache

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 3.0.0

1

dist/esm/index.js

@@ -5,2 +5,1 @@ "use strict";

exports.default = store_1.default;
//# sourceMappingURL=index.js.map

2

dist/esm/lru-store.d.ts
import { Cache, GlobalConfig } from './types';
declare function createStore<K, V>(config: Required<GlobalConfig>): Cache<K, V>;
declare function createStore<V>(config: Required<GlobalConfig>): Cache<V>;
export default createStore;

@@ -40,2 +40,1 @@ "use strict";

exports.default = createStore;
//# sourceMappingURL=lru-store.js.map
import { Cache, GlobalConfig } from './types';
declare function createStore<K, V>(config: Required<GlobalConfig>): Cache<K, V>;
declare function createStore<V>(config: Required<GlobalConfig>): Cache<V>;
export default createStore;

@@ -40,2 +40,1 @@ "use strict";

exports.default = createStore;
//# sourceMappingURL=mru-store.js.map
import { Config, Cache, GlobalConfig } from './types';
export declare const defaultConfig: Required<GlobalConfig>;
declare function createStore<K extends string, V = any>(userConfig?: Config): Cache<K, V>;
declare function createStore<V = any>(userConfig?: Config): Cache<V>;
export default createStore;

@@ -23,9 +23,9 @@ "use strict";

case 'timeout':
return timeout_store_1.default(config);
return (0, timeout_store_1.default)(config);
case 'lru':
return lru_store_1.default(config);
return (0, lru_store_1.default)(config);
case 'mru':
return mru_store_1.default(config);
return (0, mru_store_1.default)(config);
case 'tlru':
return tlru_store_1.default(config);
return (0, tlru_store_1.default)(config);
default:

@@ -36,2 +36,1 @@ throw new Error(config.policy + ' is not a supported policy.');

exports.default = createStore;
//# sourceMappingURL=store.js.map
import { Cache, GlobalConfig } from './types';
declare function createStore<K, V>(config: GlobalConfig): Cache<K, V>;
declare function createStore<V>(config: GlobalConfig): Cache<V>;
export default createStore;

@@ -6,3 +6,3 @@ "use strict";

var store = new Map();
var timer = TimeAwareMap_1.createTimeAwareMapObserver(config.timeToClear);
var timer = (0, TimeAwareMap_1.createTimeAwareMapObserver)(config.timeToClear);
function get(key) {

@@ -44,2 +44,1 @@ var val = store.get(key);

exports.default = createStore;
//# sourceMappingURL=timeout-store.js.map
import { Cache, GlobalConfig } from './types';
declare function createStore<K, V>(config: Required<GlobalConfig>): Cache<K, V>;
declare function createStore<V>(config: Required<GlobalConfig>): Cache<V>;
export default createStore;

@@ -40,2 +40,1 @@ "use strict";

exports.default = createStore;
//# sourceMappingURL=tlru-store.js.map

@@ -8,15 +8,15 @@ export interface Config {

}
export interface CreateTimeoutResult<K> {
create(key: K, removeFromStore: (key: K) => any): void;
cancel(key: K): void;
export interface CreateTimeoutResult {
create(key: string, removeFromStore: (key: string) => any): void;
cancel(key: string): void;
}
export interface Cache<K, V> {
keys(): K[];
export interface Cache<V = any> {
keys(): string[];
size(): number;
has(key: K): boolean;
get(key: K): V | null;
set(key: K, value: V): void;
remove(key: K): void;
has(key: string): boolean;
get(key: string): V | null;
set(key: string, value: V): void;
remove(key: string): void;
}
export interface GlobalConfig extends Config {
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
import { GlobalConfig } from '../types';
declare class LinkedListNode<K, V> {
next: LinkedListNode<K, V> | null;
declare class LinkedListNode<V> {
next: LinkedListNode<V> | null;
data: V;
id: K;
prev: LinkedListNode<K, V> | null;
constructor(id: K, data: any);
id: string;
prev: LinkedListNode<V> | null;
constructor(id: string, data: any);
}
export declare class LRULinkedList<K, V> {
export declare class LRULinkedList<V> {
__size: number;
HEAD: LinkedListNode<K, V> | null;
TAIL: LinkedListNode<K, V> | null;
HEAD: LinkedListNode<V> | null;
TAIL: LinkedListNode<V> | null;
limit: number;
positions: Map<K, LinkedListNode<K, V>>;
positions: Map<string, LinkedListNode<V>>;
get size(): number;
set size(size: number);
moveToHead(node: LinkedListNode<K, V>): LinkedListNode<K, V> | null;
addNodeToHead(id: K, data: V): LinkedListNode<K, V>;
remove(id: K): LinkedListNode<K, V> | null;
keys(): K[];
moveToHead(node: LinkedListNode<V>): LinkedListNode<V> | null;
addNodeToHead(id: string, data: V): LinkedListNode<V>;
remove(id: string): LinkedListNode<V> | null;
keys(): string[];
shrinkList(): void;
has(id: K): boolean;
has(id: string): boolean;
traverse(): void;
get(id: K): V | null;
get(id: string): V | null;
constructor(config: Required<GlobalConfig>);
}
export {};

@@ -51,2 +51,4 @@ "use strict";

var node = this.moveToHead(this.positions.get(id));
// overrite the data
this.positions.get(id).data = data;
return node;

@@ -163,2 +165,1 @@ }

exports.LRULinkedList = LRULinkedList;
//# sourceMappingURL=LRULinkedList.js.map
import { GlobalConfig } from '../types';
declare class LinkedListNode<K, V> {
next: LinkedListNode<K, V> | null;
declare class LinkedListNode<V> {
next: LinkedListNode<V> | null;
data: V;
id: K;
prev: LinkedListNode<K, V> | null;
constructor(id: K, data: any);
id: string;
prev: LinkedListNode<V> | null;
constructor(id: string, data: any);
}
export declare class MRULinkedList<K, V> {
export declare class MRULinkedList<V> {
__size: number;
HEAD: LinkedListNode<K, V> | null;
TAIL: LinkedListNode<K, V> | null;
HEAD: LinkedListNode<V> | null;
TAIL: LinkedListNode<V> | null;
limit: number;
positions: Map<K, LinkedListNode<K, V>>;
positions: Map<string, LinkedListNode<V>>;
get size(): number;
set size(size: number);
keys(): K[];
moveToTail(node: LinkedListNode<K, V>): LinkedListNode<K, V> | null;
moveToHead(node: LinkedListNode<K, V>): LinkedListNode<K, V> | null;
addNodeToHead(id: K, data: V): LinkedListNode<K, V>;
addNodeToTail(id: K, data: V): LinkedListNode<K, V>;
remove(id: K): LinkedListNode<K, V> | null;
keys(): string[];
moveToTail(node: LinkedListNode<V>): LinkedListNode<V> | null;
moveToHead(node: LinkedListNode<V>): LinkedListNode<V> | null;
addNodeToHead(id: string, data: V): LinkedListNode<V>;
addNodeToTail(id: string, data: V): LinkedListNode<V>;
remove(id: string): LinkedListNode<V> | null;
shrinkList(): void;
has(id: K): boolean;
has(id: string): boolean;
traverse(): void;
get(id: K): V | null;
get(id: string): V | null;
constructor(config: Required<GlobalConfig>);
}
export {};

@@ -62,2 +62,4 @@ "use strict";

var node = this.moveToHead(this.positions.get(id));
// overrite the data
this.positions.get(id).data = data;
return node;

@@ -92,2 +94,4 @@ }

var node = this.moveToTail(this.positions.get(id));
// overrite the data
this.positions.get(id).data = data;
return node;

@@ -202,2 +206,1 @@ }

exports.MRULinkedList = MRULinkedList;
//# sourceMappingURL=MRULinkedList.js.map
import { CreateTimeoutResult } from '../types';
export declare const createTimeAwareMapObserver: <K>(timeToClear: number) => CreateTimeoutResult<K>;
export declare const createTimeAwareMapObserver: (timeToClear: number) => CreateTimeoutResult;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTimeAwareMapObserver = void 0;
exports.createTimeAwareMapObserver = function (timeToClear) {
var createTimeAwareMapObserver = function (timeToClear) {
var timeouts = new Map();

@@ -22,2 +22,2 @@ return {

};
//# sourceMappingURL=TimeAwareMap.js.map
exports.createTimeAwareMapObserver = createTimeAwareMapObserver;
import { GlobalConfig, CreateTimeoutResult } from '../types';
declare class LinkedListNode<K, V> {
next: LinkedListNode<K, V> | null;
declare class LinkedListNode<V> {
next: LinkedListNode<V> | null;
data: V;
id: K;
prev: LinkedListNode<K, V> | null;
constructor(id: K, data: any);
id: string;
prev: LinkedListNode<V> | null;
constructor(id: string, data: any);
}
export declare class TLRULinkedList<K, V> {
export declare class TLRULinkedList<V> {
__size: number;
HEAD: LinkedListNode<K, V> | null;
TAIL: LinkedListNode<K, V> | null;
HEAD: LinkedListNode<V> | null;
TAIL: LinkedListNode<V> | null;
limit: number;
positions: Map<K, LinkedListNode<K, V>>;
timer: CreateTimeoutResult<K>;
positions: Map<string, LinkedListNode<V>>;
timer: CreateTimeoutResult;
get size(): number;
set size(size: number);
moveToHead(node: LinkedListNode<K, V>): LinkedListNode<K, V> | null;
addNodeToHead(id: K, data: V): LinkedListNode<K, V>;
remove(id: K): LinkedListNode<K, V> | null;
keys(): K[];
moveToHead(node: LinkedListNode<V>): LinkedListNode<V> | null;
addNodeToHead(id: string, data: V): LinkedListNode<V>;
remove(id: string): LinkedListNode<V> | null;
keys(): string[];
shrinkList(): void;
has(id: K): boolean;
has(id: string): boolean;
traverse(): void;
get(id: K): V | null;
get(id: string): V | null;
constructor(config: Required<GlobalConfig>);
}
export {};

@@ -27,3 +27,3 @@ "use strict";

this.limit = config.lruSize;
this.timer = TimeAwareMap_1.createTimeAwareMapObserver(config.timeToClear);
this.timer = (0, TimeAwareMap_1.createTimeAwareMapObserver)(config.timeToClear);
}

@@ -54,2 +54,4 @@ Object.defineProperty(TLRULinkedList.prototype, "size", {

var node = this.moveToHead(this.positions.get(id));
// overrite the data
this.positions.get(id).data = data;
return node;

@@ -177,2 +179,1 @@ }

exports.TLRULinkedList = TLRULinkedList;
//# sourceMappingURL=TLRULinkedList.js.map

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("RMStore",[],e):"object"==typeof exports?exports.RMStore=e():t.RMStore=e()}(this,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(n,s,function(e){return t[e]}.bind(null,s));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=1)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createTimeAwareMapObserver=void 0,e.createTimeAwareMapObserver=function(t){var e=new Map;return{create:function(i,n){var s=setTimeout((function(){n(i)}),t);e.set(i,s)},cancel:function(t){if(e.has(t)){var i=e.get(t);e.delete(t),clearTimeout(i)}}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(2);e.default=n.default},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.defaultConfig=void 0;var n=i(3),s=i(4),r=i(6),o=i(8);e.defaultConfig={strategy:"lru",policy:"lru",timeToClear:72e5,lruSize:500,mruSize:500},e.default=function(t){var i={};"object"==typeof t&&(i=t);var u=Object.assign({},e.defaultConfig,i);switch(u.policy){case"timeout":return n.default(u);case"lru":return s.default(u);case"mru":return r.default(u);case"tlru":return o.default(u);default:throw new Error(u.policy+" is not a supported policy.")}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(0);e.default=function(t){var e=new Map,i=n.createTimeAwareMapObserver(t.timeToClear);function s(t){return e.delete(t),i.cancel(t),!0}return{keys:function(){return Array.from(e.keys())},size:function(){return e.size},has:function(t){return e.has(t)},get:function(t){var i=e.get(t);return i||null},set:function(t,n){return e.set(t,n),i.create(t,s),!0},remove:s}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(5);e.default=function(t){var e=new n.LRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},get:function(t){var i=e.get(t);return i||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0},has:function(t){return e.has(t)}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.LRULinkedList=void 0;var n=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},s=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.lruSize}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t))return this.moveToHead(this.positions.get(t));if(this.HEAD){var i=this.HEAD,s=new n(t,e);return s.next=i,s.prev=null,i.prev=s,this.HEAD=s,this.positions.set(t,s),this.size++,s}var r=new n(t,e);return this.HEAD=r,this.TAIL||(this.TAIL=r),this.positions.set(t,r),this.size++,r},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,n=e.next;return i&&n?(i.next=n,n.prev=i,this.positions.delete(t),this.size--,e):i&&!n?(i.next=null,this.TAIL=i,this.positions.delete(t),this.size--,e):!i&&n?(n.prev=null,this.HEAD=n,this.positions.delete(t),this.size--,e):i||n?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.size--,e)},t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToHead(e);return i?i.data:null}return null},t}();e.LRULinkedList=s},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(7);e.default=function(t){var e=new n.MRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},has:function(t){return e.has(t)},get:function(t){var i=e.get(t);return i||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MRULinkedList=void 0;var n=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},s=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.mruSize}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.moveToTail=function(t){var e=this.remove(t.id);return e?this.addNodeToTail(e.id,e.data):null},t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t))return this.moveToHead(this.positions.get(t));if(this.HEAD){var i=this.HEAD,s=new n(t,e);return s.next=i,s.prev=null,i.prev=s,this.HEAD=s,this.positions.set(t,s),this.size++,s}var r=new n(t,e);return this.HEAD=r,this.TAIL||(this.TAIL=r),this.positions.set(t,r),this.size++,r},t.prototype.addNodeToTail=function(t,e){if(this.positions.has(t))return this.moveToTail(this.positions.get(t));if(this.TAIL){var i=this.TAIL,s=new n(t,e);return s.prev=i,s.next=null,i.next=s,this.TAIL=s,this.positions.set(t,s),this.size++,s}var r=new n(t,e);return this.TAIL=r,this.HEAD||(this.HEAD=r),this.positions.set(t,r),this.size++,r},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,n=e.next;return i&&n?(i.next=n,n.prev=i,this.positions.delete(t),this.size--,e):i&&!n?(i.next=null,this.TAIL=i,this.positions.delete(t),this.size--,e):!i&&n?(n.prev=null,this.HEAD=n,this.positions.delete(t),this.size--,e):i||n?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.size--,e)},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToTail(e);return i?i.data:null}return null},t}();e.MRULinkedList=s},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=i(9);e.default=function(t){var e=new n.TLRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},get:function(t){var i=e.get(t);return i||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0},has:function(t){return e.has(t)}}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.TLRULinkedList=void 0;var n=i(0),s=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},r=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.lruSize,this.timer=n.createTimeAwareMapObserver(t.timeToClear)}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t))return this.moveToHead(this.positions.get(t));var i=this.remove.bind(this);if(this.timer.create(t,i),this.HEAD){var n=this.HEAD,r=new s(t,e);return r.next=n,r.prev=null,n.prev=r,this.HEAD=r,this.positions.set(t,r),this.size++,r}var o=new s(t,e);return this.HEAD=o,this.TAIL||(this.TAIL=o),this.positions.set(t,o),this.size++,o},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,n=e.next;return i&&n?(i.next=n,n.prev=i,this.positions.delete(t),this.timer.cancel(t),this.size--,e):i&&!n?(i.next=null,this.TAIL=i,this.positions.delete(t),this.timer.cancel(t),this.size--,e):!i&&n?(n.prev=null,this.HEAD=n,this.positions.delete(t),this.timer.cancel(t),this.size--,e):i||n?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.timer.cancel(t),this.size--,e)},t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.timer.cancel(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToHead(e);return i?i.data:null}return null},t}();e.TLRULinkedList=r}]).default}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("RMStore",[],e):"object"==typeof exports?exports.RMStore=e():t.RMStore=e()}(this,(()=>(()=>{"use strict";var t={896:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=i(461);e.default=function(t){var e=new s.LRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},get:function(t){return e.get(t)||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0},has:function(t){return e.has(t)}}}},67:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=i(517);e.default=function(t){var e=new s.MRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},has:function(t){return e.has(t)},get:function(t){return e.get(t)||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0}}}},627:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.defaultConfig=void 0;var s=i(530),n=i(896),r=i(67),o=i(213);e.defaultConfig={strategy:"lru",policy:"lru",timeToClear:72e5,lruSize:500,mruSize:500},e.default=function(t){var i={};"object"==typeof t&&(i=t);var u=Object.assign({},e.defaultConfig,i);switch(u.policy){case"timeout":return(0,s.default)(u);case"lru":return(0,n.default)(u);case"mru":return(0,r.default)(u);case"tlru":return(0,o.default)(u);default:throw new Error(u.policy+" is not a supported policy.")}}},530:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=i(346);e.default=function(t){var e=new Map,i=(0,s.createTimeAwareMapObserver)(t.timeToClear);function n(t){return e.delete(t),i.cancel(t),!0}return{keys:function(){return Array.from(e.keys())},size:function(){return e.size},has:function(t){return e.has(t)},get:function(t){return e.get(t)||null},set:function(t,s){return e.set(t,s),i.create(t,n),!0},remove:n}}},213:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=i(473);e.default=function(t){var e=new s.TLRULinkedList(t);return{keys:function(){return e.keys()},size:function(){return e.size},get:function(t){return e.get(t)||null},set:function(t,i){return e.addNodeToHead(t,i),!0},remove:function(t){return e.remove(t),!0},has:function(t){return e.has(t)}}}},461:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.LRULinkedList=void 0;var i=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},s=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.lruSize}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t)){var s=this.moveToHead(this.positions.get(t));return this.positions.get(t).data=e,s}if(this.HEAD){var n=this.HEAD,r=new i(t,e);return r.next=n,r.prev=null,n.prev=r,this.HEAD=r,this.positions.set(t,r),this.size++,r}var o=new i(t,e);return this.HEAD=o,this.TAIL||(this.TAIL=o),this.positions.set(t,o),this.size++,o},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,s=e.next;return i&&s?(i.next=s,s.prev=i,this.positions.delete(t),this.size--,e):i&&!s?(i.next=null,this.TAIL=i,this.positions.delete(t),this.size--,e):!i&&s?(s.prev=null,this.HEAD=s,this.positions.delete(t),this.size--,e):i||s?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.size--,e)},t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToHead(e);return i?i.data:null}return null},t}();e.LRULinkedList=s},517:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.MRULinkedList=void 0;var i=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},s=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.mruSize}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.moveToTail=function(t){var e=this.remove(t.id);return e?this.addNodeToTail(e.id,e.data):null},t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t)){var s=this.moveToHead(this.positions.get(t));return this.positions.get(t).data=e,s}if(this.HEAD){var n=this.HEAD,r=new i(t,e);return r.next=n,r.prev=null,n.prev=r,this.HEAD=r,this.positions.set(t,r),this.size++,r}var o=new i(t,e);return this.HEAD=o,this.TAIL||(this.TAIL=o),this.positions.set(t,o),this.size++,o},t.prototype.addNodeToTail=function(t,e){if(this.positions.has(t)){var s=this.moveToTail(this.positions.get(t));return this.positions.get(t).data=e,s}if(this.TAIL){var n=this.TAIL,r=new i(t,e);return r.prev=n,r.next=null,n.next=r,this.TAIL=r,this.positions.set(t,r),this.size++,r}var o=new i(t,e);return this.TAIL=o,this.HEAD||(this.HEAD=o),this.positions.set(t,o),this.size++,o},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,s=e.next;return i&&s?(i.next=s,s.prev=i,this.positions.delete(t),this.size--,e):i&&!s?(i.next=null,this.TAIL=i,this.positions.delete(t),this.size--,e):!i&&s?(s.prev=null,this.HEAD=s,this.positions.delete(t),this.size--,e):i||s?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.size--,e)},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToTail(e);return i?i.data:null}return null},t}();e.MRULinkedList=s},473:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TLRULinkedList=void 0;var s=i(346),n=function(t,e){this.next=null,this.data=e,this.id=t,this.prev=null},r=function(){function t(t){this.__size=0,this.limit=0,this.positions=new Map,this.HEAD=null,this.TAIL=null,this.limit=t.lruSize,this.timer=(0,s.createTimeAwareMapObserver)(t.timeToClear)}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__size},set:function(t){this.__size=t,this.__size>this.limit&&this.shrinkList()},enumerable:!1,configurable:!0}),t.prototype.moveToHead=function(t){var e=this.remove(t.id);return e?this.addNodeToHead(e.id,e.data):null},t.prototype.addNodeToHead=function(t,e){if(this.positions.has(t)){var i=this.moveToHead(this.positions.get(t));return this.positions.get(t).data=e,i}var s=this.remove.bind(this);if(this.timer.create(t,s),this.HEAD){var r=this.HEAD,o=new n(t,e);return o.next=r,o.prev=null,r.prev=o,this.HEAD=o,this.positions.set(t,o),this.size++,o}var u=new n(t,e);return this.HEAD=u,this.TAIL||(this.TAIL=u),this.positions.set(t,u),this.size++,u},t.prototype.remove=function(t){if(!this.HEAD)return null;var e=this.positions.get(t);if(!e)return null;var i=e.prev,s=e.next;return i&&s?(i.next=s,s.prev=i,this.positions.delete(t),this.timer.cancel(t),this.size--,e):i&&!s?(i.next=null,this.TAIL=i,this.positions.delete(t),this.timer.cancel(t),this.size--,e):!i&&s?(s.prev=null,this.HEAD=s,this.positions.delete(t),this.timer.cancel(t),this.size--,e):i||s?null:(this.HEAD=null,this.TAIL=null,this.positions.delete(t),this.timer.cancel(t),this.size--,e)},t.prototype.keys=function(){return Array.from(this.positions.keys())},t.prototype.shrinkList=function(){for(var t=this.size-this.limit,e=this.TAIL,i=1;i<=t;i++)this.positions.delete(e.id),this.timer.cancel(e.id),this.size--,e=e.prev;e.next=null,this.TAIL=e},t.prototype.has=function(t){return!!this.positions.has(t)},t.prototype.traverse=function(){if(this.HEAD)for(var t=this.HEAD;t;)t=t.next},t.prototype.get=function(t){var e=this.positions.get(t);if(e){var i=this.moveToHead(e);return i?i.data:null}return null},t}();e.TLRULinkedList=r},346:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createTimeAwareMapObserver=void 0,e.createTimeAwareMapObserver=function(t){var e=new Map;return{create:function(i,s){var n=setTimeout((function(){s(i)}),t);e.set(i,n)},cancel:function(t){if(e.has(t)){var i=e.get(t);e.delete(t),clearTimeout(i)}}}}}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s](r,r.exports,i),r.exports}var s={};return(()=>{var t=s,e=i(627);t.default=e.default})(),s.default})()));
{
"name": "runtime-memcache",
"version": "2.1.1",
"version": "3.0.0",
"description": "A no dependency javascript runtime key-value cache store for small chunks of arbitrary data (strings, objects, numbers)",

@@ -45,26 +45,26 @@ "homepage": "https://github.com/tusharf5/runtime-memcache",

"devDependencies": {
"@types/jest": "^25.0.0",
"@types/node": "^13.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"babel-loader": "^8.0.0",
"copy-webpack-plugin": "^5.0.0",
"eslint": "^6.0.0",
"eslint-config-airbnb": "^18.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-typescript": "^3.0.0",
"eslint-formatter-pretty": "^3.0.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-loader": "^4.0.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-typescript": "^0.14.0",
"jest": "^25.0.0",
"prettier": "^2.0.0",
"ts-node": "^8.0.0",
"typescript": "^3.0.0",
"typescript-eslint-parser": "^22.0.0",
"webpack": "^4.0.0",
"webpack-cli": "^3.0.0"
"@types/jest": "~28.1.0",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "~5.30.0",
"@typescript-eslint/parser": "~5.30.0",
"babel-loader": "~8.2.0",
"copy-webpack-plugin": "11.0.0",
"eslint": "~8.20.0",
"eslint-config-airbnb": "~19.0.0",
"eslint-config-prettier": "~8.5.0",
"eslint-config-typescript": "~3.0.0",
"eslint-formatter-pretty": "~4.1.0",
"eslint-import-resolver-typescript": "~3.2.0",
"eslint-loader": "~4.0.0",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-prettier": "~4.2.0",
"eslint-plugin-typescript": "~0.14.0",
"jest": "~28.1.0",
"prettier": "~2.7.0",
"ts-node": "~10.9.0",
"typescript": "~4.6.2",
"typescript-eslint-parser": "~22.0.0",
"webpack": "~5.73.0",
"webpack-cli": "~4.10.0"
}
}

@@ -10,12 +10,12 @@ <p align="center">

<p align="center">
<a href="https://github.com/tusharf5/runtime-memcache">
<a href="https://github.com/tusharf5/runtime-memcache">
<img src="https://img.shields.io/npm/l/runtime-memcache" height="20"/>
</a>
<a href="https://github.com/tusharf5/runtime-memcache">
<a href="https://github.com/tusharf5/runtime-memcache">
<img src="https://img.shields.io/npm/v/runtime-memcache" height="20"/>
</a>
<a href="https://github.com/tusharf5/runtime-memcache">
<a href="https://github.com/tusharf5/runtime-memcache">
<img src="https://img.shields.io/npm/dt/runtime-memcache" height="20"/>
</a>
<a href="https://github.com/tusharf5/runtime-memcache">
<a href="https://github.com/tusharf5/runtime-memcache">
<img src="https://img.shields.io/bundlephobia/minzip/runtime-memcache" height="20"/>

@@ -130,3 +130,3 @@ </a>

store.set('key1', { name : 'name' }); // store the object and associate it with the provided key
store.set('key1', { name: 'name' }); // store the object and associate it with the provided key

@@ -147,5 +147,5 @@ store.get('key1'); // retrieves the object associated with this key

```typescript
import createStore from 'runtime-memcache';
import createStore, { Config } from 'runtime-memcache';
const config = {
const config: Config = {
policy: 'lru',

@@ -155,12 +155,16 @@ lruSize: 300, // cache a maximum of 300 users at a given time

const userCache = createStore(config);
interface User {
name: string;
}
const userCache = createStore<User>(config);
async function loginUser(userId: string) {
if (userCache.has(id)) {
return userCache.get(id);
if (userCache.has(userId)) {
return userCache.get(userId);
}
const user = await UserService.getUser(id);
const user = await UserService.getUser(userId);
userCache.set(id, user);
userCache.set(userId, user);

@@ -190,3 +194,4 @@ return user;

- Random Eviction Policy (RR)
- Add a warmup period for new items
For more information on caching policies read [this](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU)
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc