🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

cacheable

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cacheable - npm Package Compare versions

Comparing version
2.3.4
to
2.3.5
+17
-6
dist/index.cjs

@@ -122,4 +122,4 @@ "use strict";

const oldDeleteEvent = this.getPrefixedEvent("cache:delete" /* DELETE */);
void this._qified.unsubscribe(oldSetEvent);
void this._qified.unsubscribe(oldDeleteEvent);
void this._qified.unsubscribeMessage(oldSetEvent);
void this._qified.unsubscribeMessage(oldDeleteEvent);
}

@@ -609,10 +609,17 @@ this._namespace = namespace;

let result = false;
const finalTtl = (0, import_utils.shorthandToMilliseconds)(ttl ?? this._ttl);
const explicitTtl = (0, import_utils.shorthandToMilliseconds)(ttl);
try {
const item = { key, value, ttl: finalTtl };
const primaryTtl = (0, import_utils.getCascadingTtl)(
this._ttl,
this._primary.ttl,
explicitTtl
);
const item = { key, value, ttl: primaryTtl };
await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
const hookOverridden = item.ttl !== primaryTtl;
const promises = [];
promises.push(this._primary.set(item.key, item.value, item.ttl));
if (this._secondary) {
promises.push(this._secondary.set(item.key, item.value, item.ttl));
const secondaryTtl = hookOverridden ? item.ttl : (0, import_utils.getCascadingTtl)(this._ttl, this._secondary.ttl, explicitTtl);
promises.push(this._secondary.set(item.key, item.value, secondaryTtl));
}

@@ -953,3 +960,7 @@ if (this._nonBlocking) {

for (const item of items) {
const finalTtl = (0, import_utils.shorthandToMilliseconds)(item.ttl ?? this._ttl);
const finalTtl = (0, import_utils.getCascadingTtl)(
this._ttl,
keyv.ttl,
(0, import_utils.shorthandToMilliseconds)(item.ttl)
);
entries.push({ key: item.key, value: item.value, ttl: finalTtl });

@@ -956,0 +967,0 @@ }

@@ -92,4 +92,4 @@ // src/index.ts

const oldDeleteEvent = this.getPrefixedEvent("cache:delete" /* DELETE */);
void this._qified.unsubscribe(oldSetEvent);
void this._qified.unsubscribe(oldDeleteEvent);
void this._qified.unsubscribeMessage(oldSetEvent);
void this._qified.unsubscribeMessage(oldDeleteEvent);
}

@@ -594,10 +594,17 @@ this._namespace = namespace;

let result = false;
const finalTtl = shorthandToMilliseconds(ttl ?? this._ttl);
const explicitTtl = shorthandToMilliseconds(ttl);
try {
const item = { key, value, ttl: finalTtl };
const primaryTtl = getCascadingTtl(
this._ttl,
this._primary.ttl,
explicitTtl
);
const item = { key, value, ttl: primaryTtl };
await this.hook("BEFORE_SET" /* BEFORE_SET */, item);
const hookOverridden = item.ttl !== primaryTtl;
const promises = [];
promises.push(this._primary.set(item.key, item.value, item.ttl));
if (this._secondary) {
promises.push(this._secondary.set(item.key, item.value, item.ttl));
const secondaryTtl = hookOverridden ? item.ttl : getCascadingTtl(this._ttl, this._secondary.ttl, explicitTtl);
promises.push(this._secondary.set(item.key, item.value, secondaryTtl));
}

@@ -938,3 +945,7 @@ if (this._nonBlocking) {

for (const item of items) {
const finalTtl = shorthandToMilliseconds(item.ttl ?? this._ttl);
const finalTtl = getCascadingTtl(
this._ttl,
keyv.ttl,
shorthandToMilliseconds(item.ttl)
);
entries.push({ key: item.key, value: item.value, ttl: finalTtl });

@@ -941,0 +952,0 @@ }

{
"name": "cacheable",
"version": "2.3.4",
"version": "2.3.5",
"description": "High Performance Layer 1 / Layer 2 Caching with Keyv Storage",

@@ -32,4 +32,4 @@ "type": "module",

"@keyv/valkey": "^1.0.11",
"@qified/redis": "^0.9.0",
"lru-cache": "^11.2.7",
"@qified/redis": "^0.10.1",
"lru-cache": "^11.3.6",
"tsup": "^8.5.1",

@@ -41,5 +41,5 @@ "typescript": "^5.9.3"

"keyv": "^5.6.0",
"qified": "^0.9.0",
"@cacheable/utils": "^2.4.0",
"@cacheable/memory": "^2.0.8"
"qified": "^0.10.1",
"@cacheable/memory": "^2.0.8",
"@cacheable/utils": "^2.4.1"
},

@@ -46,0 +46,0 @@ "keywords": [

@@ -174,4 +174,5 @@ [<img align="center" src="https://cacheable.org/logo.svg" alt="Cacheable" />](https://github.com/jaredwray/cacheable)

import { Cacheable } from 'cacheable';
import {Keyv} from 'keyv';
import KeyvRedis from '@keyv/redis';
const secondary = new KeyvRedis('redis://user:pass@localhost:6379', { ttl: 1000 });
const secondary = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379'), ttl: 1000 });
const cache = new Cacheable({secondary, ttl: 100});

@@ -193,6 +194,6 @@

const primary = new Keyv({ ttl: 200 });
const secondary = new KeyvRedis('redis://user:pass@localhost:6379', { ttl: 1000 });
const secondary = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379'), ttl: 1000 });
const cache = new Cacheable({primary, secondary});
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of 100 ms and secondary store with a ttl of 1000 ms
await cache.set('key', 'value'); // sets the value in the primary store with a ttl of 200 ms and secondary store with a ttl of 1000 ms

@@ -199,0 +200,0 @@ await sleep(200); // wait for .2 seconds