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

@resolid/cache

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@resolid/cache - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+1
-0
dist/index.d.mts

@@ -24,2 +24,3 @@ import { t as CacheStore } from "./types-BvLwqpdf.mjs";

set<T>(key: string, value: T, ttl?: number): Promise<boolean>;
getOrSet<T>(key: string, factory: () => T | Promise<T>, ttl?: number): Promise<T>;
del(key: string): Promise<boolean>;

@@ -26,0 +27,0 @@ clear(): Promise<boolean>;

+1
-1

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

import{t as e}from"./null-cache-DGPituGm.mjs";function t(e){let t=e.split(`?`)[0]?.replace(/[/\\]/g,`:`).replace(/:+/g,`:`).replace(/^:|:$/g,``);if(!t)throw Error(`Cache key cannot be empty after normalization`);return t}var n=class{_store;_serializer;_defaultTtl;constructor({store:t=new e,serializer:n={serialize:JSON.stringify,deserialize:JSON.parse},defaultTtl:r}={}){this._store=t,this._serializer=n,this._defaultTtl=r}async get(e,n){let r=await this._store.get(t(e));return r===void 0?n:this._serializer.deserialize(r)}set(e,n,r){return this._store.set(t(e),this._serializer.serialize(n),r??this._defaultTtl)}del(e){return this._store.del(t(e))}clear(){return this._store.clear()}async getMultiple(e,n){return this._store.getMultiple?(await this._store.getMultiple(e.map(t))).map(e=>e===void 0?n:this._serializer.deserialize(e)):Promise.all(e.map(e=>this.get(e,n)))}async setMultiple(e,n){return this._store.setMultiple?this._store.setMultiple(Object.entries(e).reduce((e,[n,r])=>(e[t(n)]=this._serializer.serialize(r),e),{}),n):(await Promise.all(Object.entries(e).map(([e,t])=>this.set(e,t,n)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(t)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(t(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{n as Cacher};
import{t as e}from"./null-cache-DGPituGm.mjs";function t(e){let t=e.split(`?`)[0]?.replace(/[/\\]/g,`:`).replace(/:+/g,`:`).replace(/^:|:$/g,``);if(!t)throw Error(`Cache key cannot be empty after normalization`);return t}var n=class{_store;_serializer;_defaultTtl;constructor({store:t=new e,serializer:n={serialize:JSON.stringify,deserialize:JSON.parse},defaultTtl:r}={}){this._store=t,this._serializer=n,this._defaultTtl=r}async get(e,n){let r=await this._store.get(t(e));return r===void 0?n:this._serializer.deserialize(r)}set(e,n,r){return this._store.set(t(e),this._serializer.serialize(n),r??this._defaultTtl)}async getOrSet(e,t,n){let r=await this.get(e);if(r!==void 0)return r;let i=await t();return await this.set(e,i,n),i}del(e){return this._store.del(t(e))}clear(){return this._store.clear()}async getMultiple(e,n){return this._store.getMultiple?(await this._store.getMultiple(e.map(t))).map(e=>e===void 0?n:this._serializer.deserialize(e)):Promise.all(e.map(e=>this.get(e,n)))}async setMultiple(e,n){return this._store.setMultiple?this._store.setMultiple(Object.entries(e).reduce((e,[n,r])=>(e[t(n)]=this._serializer.serialize(r),e),{}),n):(await Promise.all(Object.entries(e).map(([e,t])=>this.set(e,t,n)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(t)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(t(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{n as Cacher};

@@ -27,2 +27,2 @@ import { t as CacheStore } from "./types-BvLwqpdf.mjs";

//#endregion
export { CacheStore, MemoryCache, NullCache };
export { type CacheStore, MemoryCache, NullCache };
{
"name": "@resolid/cache",
"version": "1.1.0",
"version": "1.2.0",
"private": false,

@@ -5,0 +5,0 @@ "description": "Type-safe Async Cache for TypeScript",

@@ -15,3 +15,3 @@ # Type-safe Async Cache for TypeScript

- Fully typed with TypeScript — no `any`.
- Supports get/set/del/clear operations.
- Supports get/getOrSet/set/del/clear operations.
- Supports batch operations: getMultiple, setMultiple, delMultiple.

@@ -46,2 +46,5 @@ - Optional TTL for automatic expiration.

// Get or set with factory
const user = await cache.getOrSet("user:1", () => fetchUser(1), 60);
// Check existence

@@ -48,0 +51,0 @@ const exists = await cache.has("foo"); // -> true