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

cachu

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachu - npm Package Compare versions

Comparing version 5.3.0-canary.0 to 5.3.0

types/caches/RedisCache.d.ts

2

dist/index.js

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

var S=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),U=(n,e)=>{for(var a in e)p(n,a,{get:e[a],enumerable:!0})},v=(n,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of O(e))!E.call(n,d)&&d!==a&&p(n,d,{get:()=>e[d],enumerable:!(i=R(e,d))||i.enumerable});return n};var k=(n,e,a)=>(a=n!=null?S(C(n)):{},v(e||!n||!n.__esModule?p(a,"default",{value:n,enumerable:!0}):a,n)),L=n=>v(p({},"__esModule",{value:!0}),n);var b=G((ue,D)=>{var f=1e3,y=f*60,m=y*60,u=m*24,N=u*7,B=u*365.25;D.exports=function(n,e){e=e||{};var a=typeof n;if(a==="string"&&n.length>0)return F(n);if(a==="number"&&isFinite(n))return e.long?I(n):H(n);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(n))};function F(n){if(n=String(n),!(n.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(n);if(!!e){var a=parseFloat(e[1]),i=(e[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return a*B;case"weeks":case"week":case"w":return a*N;case"days":case"day":case"d":return a*u;case"hours":case"hour":case"hrs":case"hr":case"h":return a*m;case"minutes":case"minute":case"mins":case"min":case"m":return a*y;case"seconds":case"second":case"secs":case"sec":case"s":return a*f;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function H(n){var e=Math.abs(n);return e>=u?Math.round(n/u)+"d":e>=m?Math.round(n/m)+"h":e>=y?Math.round(n/y)+"m":e>=f?Math.round(n/f)+"s":n+"ms"}function I(n){var e=Math.abs(n);return e>=u?x(n,e,u,"day"):e>=m?x(n,e,m,"hour"):e>=y?x(n,e,y,"minute"):e>=f?x(n,e,f,"second"):n+" ms"}function x(n,e,a,i){var d=e>=a*1.5;return Math.round(n/a)+" "+i+(d?"s":"")}});var V={};U(V,{MemoryCache:()=>z});module.exports=L(V);var M=k(b()),K=(n={})=>{let e=new Map,a={},i,d=typeof n.maxAge=="number"?n.maxAge*1e3:typeof n.maxAge=="string"?(0,M.default)(n.maxAge):6e5,l=n.maxAmount??1e4,h=async()=>{e.forEach(async(t,r)=>{Date.now()-t.age>d&&e.delete(r)})},A=async()=>{let t=0,r=0;e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r=o)}),e.delete(r)};return{set:async(t,r,s)=>{if(a.set&&await a.set(t,r,s),e.has(t))return;d!==1/0&&await h(),e.size>l&&await A();let o={value:r,age:Date.now(),...typeof s=="string"?{maxAge:(0,M.default)(s)}:typeof s=="number"&&{maxAge:s*1e3}};return e.set(t,o),i={key:t,...o},{key:t,...o}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await h();let r=[];for(let s of t){let o=s[0],c=s[1],g=s[2];if(e.has(o)){r.push(void 0);continue}let w={value:c,age:Date.now(),...typeof g=="string"?{maxAge:(0,M.default)(g)}:typeof g=="number"&&{maxAge:g*1e3}};e.size>l&&await A(),e.set(o,w),i={key:o,...w},r.push({key:o,...w})}return r},get:async(t,r={})=>{a.get&&await a.get(t,r);let s=e.get(t);if(!!s){if(r.validate!==!1&&(s.maxAge?Date.now()-s.age>s.maxAge:Date.now()-s.age>d)){e.delete(t);return}return r.delete&&e.delete(t),{key:t,...s}}},getMany:async(t,r={})=>{a.getMany&&await a.getMany(t,r);let s=[];for(let o of t){let c=e.get(o);if(!c){s.push(void 0);continue}if(r.validate!==!1&&(c.maxAge?Date.now()-c.age>c.maxAge:Date.now()-c.age>d)){e.delete(o),s.push(void 0);continue}r.delete&&e.delete(o),s.push({key:o,...c})}return r.reverse?s.reverse():s},update:async(t,r,s)=>{a.update&&await a.update(t,r,s??{});let o=e.get(t);if(!o)return;let c={value:r,age:s&&s.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(t,c),i={key:t,...c}},updateMany:async(t,r)=>{a.updateMany&&await a.updateMany(t,r??{});for(let s of t){let o=e.get(s[0]);if(!o)return;let c={value:s[1],age:r&&r.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(s[0],c),i={key:s[0],...c}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let r of t)e.delete(r)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let r of[...e.values()])t.push(r.value);return t},clear:async()=>(a.clear&&await a.clear(),await h()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),r=Buffer.from(t);return Buffer.byteLength(r)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,M.default)(t):6e5,await h()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await h()),l),newest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},oldest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{(t===0||s.age<t)&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},on:async(t,r)=>{a[t]=r},dump:async()=>{if(e.size===0)return[];let t=[],r=[...e.keys()];for(let s of r){let o=e.get(s);!o||t.push({key:s,...o})}return t}}},z=K;
var S=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),U=(n,e)=>{for(var a in e)p(n,a,{get:e[a],enumerable:!0})},v=(n,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of O(e))!E.call(n,d)&&d!==a&&p(n,d,{get:()=>e[d],enumerable:!(i=R(e,d))||i.enumerable});return n};var k=(n,e,a)=>(a=n!=null?S(C(n)):{},v(e||!n||!n.__esModule?p(a,"default",{value:n,enumerable:!0}):a,n)),L=n=>v(p({},"__esModule",{value:!0}),n);var b=G((ue,D)=>{var f=1e3,y=f*60,m=y*60,u=m*24,N=u*7,B=u*365.25;D.exports=function(n,e){e=e||{};var a=typeof n;if(a==="string"&&n.length>0)return F(n);if(a==="number"&&isFinite(n))return e.long?I(n):H(n);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(n))};function F(n){if(n=String(n),!(n.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(n);if(!!e){var a=parseFloat(e[1]),i=(e[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return a*B;case"weeks":case"week":case"w":return a*N;case"days":case"day":case"d":return a*u;case"hours":case"hour":case"hrs":case"hr":case"h":return a*m;case"minutes":case"minute":case"mins":case"min":case"m":return a*y;case"seconds":case"second":case"secs":case"sec":case"s":return a*f;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function H(n){var e=Math.abs(n);return e>=u?Math.round(n/u)+"d":e>=m?Math.round(n/m)+"h":e>=y?Math.round(n/y)+"m":e>=f?Math.round(n/f)+"s":n+"ms"}function I(n){var e=Math.abs(n);return e>=u?w(n,e,u,"day"):e>=m?w(n,e,m,"hour"):e>=y?w(n,e,y,"minute"):e>=f?w(n,e,f,"second"):n+" ms"}function w(n,e,a,i){var d=e>=a*1.5;return Math.round(n/a)+" "+i+(d?"s":"")}});var V={};U(V,{MemoryCache:()=>z});module.exports=L(V);var M=k(b()),K=(n={})=>{let e=new Map,a={},i,d=typeof n.maxAge=="number"?n.maxAge*1e3:typeof n.maxAge=="string"?(0,M.default)(n.maxAge):6e5,l=n.maxAmount??1e4,h=async()=>{e.forEach(async(t,r)=>{Date.now()-t.age>d&&e.delete(r)})},A=async()=>{let t=0,r=0;e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r=o)}),e.delete(r)};return{set:async(t,r,s)=>{if(a.set&&await a.set(t,r,s),e.has(t))return;d!==1/0&&await h(),e.size>l&&await A();let o={value:r,age:Date.now(),...typeof s=="string"?{maxAge:(0,M.default)(s)}:typeof s=="number"&&{maxAge:s*1e3}};return e.set(t,o),i={key:t,...o},{key:t,...o}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await h();let r=[];for(let s of t){let o=s[0],c=s[1],g=s[2];if(e.has(o)){r.push(void 0);continue}let x={value:c,age:Date.now(),...typeof g=="string"?{maxAge:(0,M.default)(g)}:typeof g=="number"&&{maxAge:g*1e3}};e.size>l&&await A(),e.set(o,x),i={key:o,...x},r.push({key:o,...x})}return r},get:async(t,r={})=>{a.get&&await a.get(t,r);let s=e.get(t);if(!!s){if(r.validate!==!1&&(s.maxAge?Date.now()-s.age>s.maxAge:Date.now()-s.age>d)){e.delete(t);return}return r.delete&&e.delete(t),{key:t,...s}}},getMany:async(t,r={})=>{a.getMany&&await a.getMany(t,r);let s=[];for(let o of t){let c=e.get(o);if(!c){s.push(void 0);continue}if(r.validate!==!1&&(c.maxAge?Date.now()-c.age>c.maxAge:Date.now()-c.age>d)){e.delete(o),s.push(void 0);continue}r.delete&&e.delete(o),s.push({key:o,...c})}return r.reverse?s.reverse():s},update:async(t,r,s)=>{a.update&&await a.update(t,r,s??{});let o=e.get(t);if(!o)return;let c={value:r,age:s&&s.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(t,c),i={key:t,...c}},updateMany:async(t,r)=>{a.updateMany&&await a.updateMany(t,r??{});for(let s of t){let o=e.get(s[0]);if(!o)return;let c={value:s[1],age:r&&r.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(s[0],c),i={key:s[0],...c}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let r of t)e.delete(r)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let r of[...e.values()])t.push(r.value);return t},clear:async()=>(a.clear&&await a.clear(),await h()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),r=Buffer.from(t);return Buffer.byteLength(r)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,M.default)(t):6e5,await h()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await h()),l),newest:async()=>{if(a.newest&&await a.newest(),e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},oldest:async()=>{if(a.oldest&&await a.oldest(),e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{(t===0||s.age<t)&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},on:async(t,r)=>{a[t]=r},dump:async()=>{if(a.dump&&await a.dump(),e.size===0)return[];let t=[],r=[...e.keys()];for(let s of r){let o=e.get(s);!o||t.push({key:s,...o})}return t}}},z=K;
{
"name": "cachu",
"version": "5.3.0-canary.0",
"version": "5.3.0",
"description": "🦝 Simple, Minimalistic KV Cache",

@@ -5,0 +5,0 @@ "types": "./types/index.d.ts",

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

declare type Key = {}
declare type Key = any
declare type Value = {}
declare type Value = any

@@ -79,3 +79,6 @@ declare type Record = {

| 'maxAmount'
| 'newest'
| 'oldest'
| 'on'
| 'dump'

@@ -86,3 +89,3 @@ declare type OnMethod = (event: Event, action: Function) => Promise<void>

declare type MemoryCache = (config: {
declare type MemoryCache = (config?: {
maxAge?: string | number,

@@ -89,0 +92,0 @@ maxAmount?: number

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

export { default as MemoryCache } from './caches/MemoryCache'
export { default as MemoryCache } from './caches/MemoryCache'
export { default as RedisCache } from './caches/RedisCache'
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