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

cacheable

Package Overview
Dependencies
Maintainers
1
Versions
22
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 1.3.0 to 1.5.0

8

dist/index.d.ts

@@ -53,2 +53,3 @@ import { Keyv, KeyvStoreAdapter } from 'keyv';

lruSize?: number;
checkInterval?: number;
};

@@ -71,2 +72,4 @@ declare class CacheableMemory {

private _lruSize;
private _checkInterval;
private _interval;
constructor(options?: CacheableMemoryOptions);

@@ -79,2 +82,4 @@ get ttl(): number;

set lruSize(value: number);
get checkInterval(): number;
set checkInterval(value: number);
get size(): number;

@@ -94,2 +99,5 @@ get keys(): IterableIterator<string>;

lruResize(): void;
checkExpiration(): void;
startIntervalCheck(): void;
stopIntervalCheck(): void;
private isPrimitive;

@@ -96,0 +104,0 @@ private concatStores;

@@ -268,4 +268,11 @@ // src/index.ts

_ttl = 0;
// Turned off by default
_useClone = true;
// Turned on by default
_lruSize = 0;
// Turned off by default
_checkInterval = 0;
// Turned off by default
_interval = 0;
// Turned off by default
constructor(options) {

@@ -281,2 +288,6 @@ if (options?.ttl) {

}
if (options?.checkInterval) {
this._checkInterval = options.checkInterval;
}
this.startIntervalCheck();
}

@@ -302,2 +313,8 @@ get ttl() {

}
get checkInterval() {
return this._checkInterval;
}
set checkInterval(value) {
this._checkInterval = value;
}
get size() {

@@ -460,2 +477,24 @@ return this._hash0.size + this._hash1.size + this._hash2.size + this._hash3.size + this._hash4.size + this._hash5.size + this._hash6.size + this._hash7.size + this._hash8.size + this._hash9.size;

}
checkExpiration() {
const stores = this.concatStores();
for (const item of stores.values()) {
if (item.expires && Date.now() > item.expires) {
this.delete(item.key);
}
}
}
startIntervalCheck() {
if (this._checkInterval > 0) {
this._interval = setInterval(() => {
this.checkExpiration();
}, this._checkInterval);
}
}
stopIntervalCheck() {
if (this._interval) {
clearInterval(this._interval);
}
this._interval = 0;
this._checkInterval = 0;
}
isPrimitive(value) {

@@ -462,0 +501,0 @@ const result = false;

3

package.json
{
"name": "cacheable",
"version": "1.3.0",
"version": "1.5.0",
"description": "Simple Caching Engine using Keyv",

@@ -21,2 +21,3 @@ "type": "module",

"@keyv/redis": "^3.0.1",
"@types/node": "^22.6.1",
"@vitest/coverage-v8": "^2.1.1",

@@ -23,0 +24,0 @@ "lru-cache": "^11.0.1",

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

* `setMany([{key, value, ttl?}])`: Sets multiple values in the cache.
* `get(key | [keys])`: Gets a value from the cache.
* `get(key)`: Gets a value from the cache.
* `getMany([keys])`: Gets multiple values from the cache.
* `has(key | [key])`: Checks if a value exists in the cache.
* `has(key)`: Checks if a value exists in the cache.
* `hasMany([keys])`: Checks if multiple values exist in the cache.
* `take(key)`: Takes a value from the cache and deletes it.
* `takeMany([keys])`: Takes multiple values from the cache and deletes them.
* `delete(key | [key])`: Deletes a value from the cache.
* `delete(key)`: Deletes a value from the cache.
* `deleteMany([keys])`: Deletes multiple values from the cache.

@@ -199,2 +199,11 @@ * `clear()`: Clears the cache stores. Be careful with this as it will clear both layer 1 and layer 2.

By default we use lazy expiration deletion which means on `get` and `getMany` type functions we look if it is expired and then delete it. If you want to have a more aggressive expiration policy you can set the `checkInterval` property to a value greater than `0` which will check for expired keys at the interval you set.
### CacheableMemory Options
* `ttl`: The time to live for the cache in milliseconds.
* `useClones`: If the cache should use clones for the values. Default is `true`.
* `lruSize`: The size of the LRU cache. Default is `0` which is unlimited.
* `checkInterval`: The interval to check for expired keys in milliseconds. Default is `0` which is disabled.
### CacheableMemory API

@@ -209,2 +218,5 @@

* `keys()`: The keys in the cache.
* `checkExpired()`: Checks for expired keys in the cache. This is used by the `checkInterval` property.
* `startIntervalCheck()`: Starts the interval check for expired keys if `checkInterval` is above 0 ms.
* `stopIntervalCheck()`: Stops the interval check for expired keys.

@@ -211,0 +223,0 @@

Sorry, the diff of this file is not supported yet

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