@resolid/cache
Advanced tools
| //#region src/stores/types.d.ts | ||
| interface CacheStore { | ||
| get: (key: string) => Promise<string | undefined>; | ||
| set: (key: string, value: string, ttl?: number) => Promise<boolean>; | ||
| del: (key: string) => Promise<boolean>; | ||
| clear: () => Promise<boolean>; | ||
| getMultiple?: (keys: string[]) => Promise<(string | undefined)[]>; | ||
| setMultiple?: (values: Record<string, string>, ttl?: number) => Promise<boolean>; | ||
| delMultiple?: (keys: string[]) => Promise<boolean>; | ||
| has?: (key: string) => Promise<boolean>; | ||
| dispose?: () => Promise<void> | void; | ||
| } | ||
| //#endregion | ||
| export { CacheStore as t }; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { t as CacheStore } from "./types-D3cbGkJC.mjs"; | ||
| import { t as CacheStore } from "./types-BvLwqpdf.mjs"; | ||
@@ -3,0 +3,0 @@ //#region src/index.d.ts |
+1
-1
@@ -1,1 +0,1 @@ | ||
| import{t as e}from"./null-cache-DGPituGm.mjs";import{destr as t}from"destr";const n=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 r=class{_store;_defaultTtl;constructor({store:t=new e,defaultTtl:n}={}){this._store=t,this._defaultTtl=n}async get(e,r){let i=await this._store.get(n(e));return i===void 0?r:t(i)}set(e,t,r){return this._store.set(n(e),JSON.stringify(t),r??this._defaultTtl)}del(e){return this._store.del(n(e))}clear(){return this._store.clear()}async getMultiple(e,r){return this._store.getMultiple?(await this._store.getMultiple(e.map(n))).map(e=>e===void 0?r:t(e)):Promise.all(e.map(e=>this.get(e,r)))}async setMultiple(e,t){if(this._store.setMultiple){let r=Object.entries(e).reduce((e,[t,r])=>(e[n(t)]=JSON.stringify(r),e),{});return this._store.setMultiple(r,t)}return(await Promise.all(Object.entries(e).map(([e,n])=>this.set(e,n,t)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(n)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(n(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{r as Cacher}; | ||
| import{t as e}from"./null-cache-DGPituGm.mjs";import{destr as t}from"destr";const n=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 r=class{_store;_defaultTtl;constructor({store:t=new e,defaultTtl:n}={}){this._store=t,this._defaultTtl=n}async get(e,r){let i=await this._store.get(n(e));return i===void 0?r:t(i)}set(e,t,r){return this._store.set(n(e),JSON.stringify(t),r??this._defaultTtl)}del(e){return this._store.del(n(e))}clear(){return this._store.clear()}async getMultiple(e,r){return this._store.getMultiple?(await this._store.getMultiple(e.map(n))).map(e=>e===void 0?r:t(e)):Promise.all(e.map(e=>this.get(e,r)))}async setMultiple(e,t){if(this._store.setMultiple){let r=Object.entries(e).reduce((e,[t,r])=>(e[n(t)]=JSON.stringify(r),e),{});return this._store.setMultiple(r,t)}return(await Promise.all(Object.entries(e).map(([e,n])=>this.set(e,n,t)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(n)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(n(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{r as Cacher}; |
@@ -1,2 +0,2 @@ | ||
| import { t as CacheStore } from "./types-D3cbGkJC.mjs"; | ||
| import { t as CacheStore } from "./types-BvLwqpdf.mjs"; | ||
@@ -3,0 +3,0 @@ //#region src/stores/memory-cache.d.ts |
+4
-4
| { | ||
| "name": "@resolid/cache", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "private": false, | ||
@@ -36,3 +36,4 @@ "description": "Type-safe Async Cache for TypeScript", | ||
| "import": "./dist/stores.mjs" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
@@ -48,4 +49,3 @@ "publishConfig": { | ||
| "devDependencies": { | ||
| "tsdown": "^0.20.3", | ||
| "typescript": "^5.9.3" | ||
| "tsdown": "^0.21.5" | ||
| }, | ||
@@ -52,0 +52,0 @@ "engines": { |
| //#region src/stores/types.d.ts | ||
| interface CacheStore { | ||
| get: (key: string) => Promise<string | undefined>; | ||
| set: (key: string, value: string, ttl?: number) => Promise<boolean>; | ||
| del: (key: string) => Promise<boolean>; | ||
| clear: () => Promise<boolean>; | ||
| getMultiple?: (keys: string[]) => Promise<(string | undefined)[]>; | ||
| setMultiple?: (values: Record<string, string>, ttl?: number) => Promise<boolean>; | ||
| delMultiple?: (keys: string[]) => Promise<boolean>; | ||
| has?: (key: string) => Promise<boolean>; | ||
| dispose?: () => Promise<void> | void; | ||
| } | ||
| //#endregion | ||
| export { CacheStore as t }; |
9028
0.14%1
-50%