@philiprehberger/cache-kit 0.1.1 → 0.2.0
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.
- package/README.md +36 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -86,6 +86,42 @@ const data = cache.dump(); // serialize to JSON
|
|
|
86
86
|
cache.load(data); // restore from JSON
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### `createCache<V>(options?: CacheOptions): Cache<V>`
|
|
92
|
+
|
|
93
|
+
| Method | Signature | Description |
|
|
94
|
+
|--------|-----------|-------------|
|
|
95
|
+
| `set` | `(key: string, value: V, opts?: SetOptions) => void` | Store a value. |
|
|
96
|
+
| `get` | `(key: string) => V \| undefined` | Retrieve a value. Returns `undefined` if missing or expired. |
|
|
97
|
+
| `has` | `(key: string) => boolean` | Check if a key exists and is not expired. |
|
|
98
|
+
| `delete` | `(key: string) => boolean` | Remove a key. Returns `true` if it existed. |
|
|
99
|
+
| `clear` | `() => void` | Remove all entries and reset stats. |
|
|
100
|
+
| `invalidateTag` | `(tag: string) => number` | Remove all entries with the given tag. Returns count removed. |
|
|
101
|
+
| `wrap` | `(keyPrefix, fn, opts?) => (...args) => Promise` | Memoize an async function with cache. |
|
|
102
|
+
| `stats` | `() => CacheStats` | Get hit/miss/size statistics. |
|
|
103
|
+
| `dump` | `() => SerializedCache` | Serialize cache contents for persistence. |
|
|
104
|
+
| `load` | `(data: SerializedCache) => void` | Restore cache from serialized data. |
|
|
105
|
+
|
|
106
|
+
### `CacheOptions`
|
|
107
|
+
|
|
108
|
+
| Property | Type | Default | Description |
|
|
109
|
+
|----------|------|---------|-------------|
|
|
110
|
+
| `maxItems` | `number` | `Infinity` | Max entries before LRU eviction. |
|
|
111
|
+
| `defaultTTL` | `string \| number` | None | Default TTL for all entries. |
|
|
112
|
+
|
|
113
|
+
### `SetOptions`
|
|
114
|
+
|
|
115
|
+
| Property | Type | Description |
|
|
116
|
+
|----------|------|-------------|
|
|
117
|
+
| `ttl` | `string \| number` | Time-to-live (e.g. `"5m"`, `60000`). |
|
|
118
|
+
| `tags` | `string[]` | Tags for group invalidation. |
|
|
119
|
+
| `staleWhileRevalidate` | `string \| number` | Window before expiry where stale data is served while refreshing. |
|
|
120
|
+
|
|
121
|
+
### Duration Strings
|
|
122
|
+
|
|
123
|
+
`"100ms"`, `"30s"`, `"5m"`, `"1h"`, `"1d"` — or pass milliseconds as a number.
|
|
124
|
+
|
|
89
125
|
## License
|
|
90
126
|
|
|
91
127
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@philiprehberger/cache-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "In-memory LRU cache with TTL, stale-while-revalidate, and tag invalidation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"build": "tsup",
|
|
26
26
|
"dev": "tsup --watch",
|
|
27
27
|
"typecheck": "tsc --noEmit",
|
|
28
|
-
"prepublishOnly": "npm run build"
|
|
28
|
+
"prepublishOnly": "npm run build",
|
|
29
|
+
"test": "node --test src/__tests__/index.test.mjs"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"tsup": "^8.0.0",
|