@resolid/cache 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +85 -0
  2. package/package.json +8 -8
package/README.md CHANGED
@@ -5,6 +5,91 @@
5
5
 
6
6
  <b>[Documentation](https://www.resolid.tech/docs/cache)</b> | [Framework Bundle](https://github.com/resolid/framework)
7
7
 
8
+ ## Type-safe Async Cache for TypeScript
9
+
10
+ A fully-typed, flexible cache system for modern TypeScript projects.
11
+ Supports single and batch operations, optional TTL, and pluggable storage backends.
12
+ Designed for libraries, frameworks, and applications needing predictable async caching.
13
+
14
+ ### Feature
15
+
16
+ - Fully typed with TypeScript — no `any`.
17
+ - Supports get/set/del/clear operations.
18
+ - Supports batch operations: getMultiple, setMultiple, delMultiple.
19
+ - Optional TTL for automatic expiration.
20
+ - Pluggable store backend (default is `nullCache`).
21
+ - Detects existence of keys via `has`.
22
+ - Handles disposal of resources via `dispose`.
23
+
24
+ ### Installation
25
+
26
+ ```shell
27
+ pnpm add @resolid/cache
28
+ # or
29
+ npm install @resolid/cache
30
+ # or
31
+ yarn add @resolid/cache
32
+ # or
33
+ bun add @resolid/cache
34
+ ```
35
+
36
+ ### Usage
37
+
38
+ ```js
39
+ import { createCache } from "@resolid/cache";
40
+
41
+ const cache = createCache({ defaultTtl: 1000 });
42
+
43
+ // Single set/get
44
+ await cache.set("foo", { a: 1 });
45
+ const value = await cache.get("foo"); // -> { a: 1 }
46
+
47
+ // Check existence
48
+ const exists = await cache.has("foo"); // -> true
49
+
50
+ // Batch set/get
51
+ await cache.setMultiple({ key1: 1, key2: 2 });
52
+ const values = await cache.getMultiple(["key1", "key2"]); // -> [1, 2]
53
+
54
+ // Delete
55
+ await cache.del("foo");
56
+ await cache.delMultiple(["key1", "key2"]);
57
+
58
+ // Clear all
59
+ await cache.clear();
60
+
61
+ // Dispose store if necessary
62
+ await cache.dispose();
63
+ ```
64
+
65
+ ### Options
66
+
67
+ ```ts
68
+ export type CreateCacheOptions = {
69
+ store?: CacheStore; // Custom storage backend
70
+ defaultTtl?: number; // Default TTL in seconds
71
+ };
72
+ ```
73
+
74
+ ### Store Interface
75
+
76
+ Your custom store should implement `CacheStore`:
77
+
78
+ ```ts
79
+ export interface CacheStore {
80
+ get(key: string): Promise<string | undefined>;
81
+ set(key: string, value: string, ttl?: number): Promise<boolean>;
82
+ del(key: string): Promise<boolean>;
83
+ clear(): Promise<boolean>;
84
+
85
+ getMultiple?(keys: string[]): Promise<(string | undefined)[]>;
86
+ setMultiple?(values: Record<string, string>, ttl?: number): Promise<boolean>;
87
+ delMultiple?(keys: string[]): Promise<boolean>;
88
+ has?(key: string): Promise<boolean>;
89
+ dispose?(): Promise<void> | void;
90
+ }
91
+ ```
92
+
8
93
  ## License
9
94
 
10
95
  MIT License (MIT). Please see [LICENSE](./LICENSE) for more information.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolid/cache",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "The Resolid Cache package.",
6
6
  "keywords": [
@@ -44,12 +44,6 @@
44
44
  "files": [
45
45
  "dist"
46
46
  ],
47
- "scripts": {
48
- "build": "tsdown",
49
- "lint": "eslint .",
50
- "test": "vitest run",
51
- "typecheck": "tsc --noEmit"
52
- },
53
47
  "dependencies": {
54
48
  "destr": "^2.0.5",
55
49
  "quick-lru": "^7.3.0"
@@ -66,5 +60,11 @@
66
60
  "publishConfig": {
67
61
  "access": "public",
68
62
  "provenance": true
63
+ },
64
+ "scripts": {
65
+ "build": "tsdown",
66
+ "lint": "eslint .",
67
+ "test": "vitest run",
68
+ "typecheck": "tsc --noEmit"
69
69
  }
70
- }
70
+ }