@philiprehberger/cache-kit 0.1.1 → 0.2.2

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 +39 -3
  2. package/package.json +6 -5
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # @philiprehberger/cache-kit
1
+ # @philiprehberger/ts-cache-kit
2
2
 
3
3
  In-memory LRU cache with TTL, stale-while-revalidate, and tag invalidation.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @philiprehberger/cache-kit
8
+ npm install @philiprehberger/ts-cache-kit
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -13,7 +13,7 @@ npm install @philiprehberger/cache-kit
13
13
  ### Basic
14
14
 
15
15
  ```ts
16
- import { createCache } from '@philiprehberger/cache-kit';
16
+ import { createCache } from '@philiprehberger/ts-cache-kit';
17
17
 
18
18
  const cache = createCache({ maxItems: 1000, defaultTTL: '5m' });
19
19
 
@@ -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.1.1",
3
+ "version": "0.2.2",
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",
@@ -42,11 +43,11 @@
42
43
  "license": "MIT",
43
44
  "repository": {
44
45
  "type": "git",
45
- "url": "git+https://github.com/philiprehberger/cache-kit.git"
46
+ "url": "git+https://github.com/philiprehberger/ts-cache-kit.git"
46
47
  },
47
- "homepage": "https://github.com/philiprehberger/cache-kit#readme",
48
+ "homepage": "https://github.com/philiprehberger/ts-cache-kit#readme",
48
49
  "bugs": {
49
- "url": "https://github.com/philiprehberger/cache-kit/issues"
50
+ "url": "https://github.com/philiprehberger/ts-cache-kit/issues"
50
51
  },
51
52
  "author": "Philip Rehberger",
52
53
  "engines": {