spooder 5.1.11 → 5.1.12
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 +6 -1
- package/package.json +1 -1
- package/src/api.ts +6 -2
package/README.md
CHANGED
|
@@ -1784,6 +1784,10 @@ server.route('/', cache.file('./index.html'));
|
|
|
1784
1784
|
|
|
1785
1785
|
// Use with server routes for dynamic content
|
|
1786
1786
|
server.route('/dynamic', async (req) => cache.request(req, 'dynamic-page', () => 'Dynamic Content'));
|
|
1787
|
+
|
|
1788
|
+
// Disable caching (useful for development mode)
|
|
1789
|
+
const devCache = cache_http({ enabled: process.env.SPOODER_ENV !== 'dev' });
|
|
1790
|
+
server.route('/no-cache', devCache.file('./index.html')); // Always reads from disk
|
|
1787
1791
|
```
|
|
1788
1792
|
|
|
1789
1793
|
The `cache_http()` function returns an object with two methods:
|
|
@@ -1827,7 +1831,8 @@ server.route('/api/stats', async (req) => {
|
|
|
1827
1831
|
| `max_size` | `number` | `5242880` (5 MB) | Maximum total size of all cached files in bytes |
|
|
1828
1832
|
| `use_etags` | `boolean` | `true` | Generate and use ETag headers for cache validation |
|
|
1829
1833
|
| `headers` | `Record<string, string>` | `{}` | Additional HTTP headers to include in responses |
|
|
1830
|
-
| `use_canary_reporting` | `boolean` | `false` | Reports faults to canary (see below)
|
|
1834
|
+
| `use_canary_reporting` | `boolean` | `false` | Reports faults to canary (see below) |
|
|
1835
|
+
| `enabled` | `boolean` | `true` | When false, content is generated but not stored
|
|
1831
1836
|
|
|
1832
1837
|
#### Canary Reporting
|
|
1833
1838
|
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -128,6 +128,7 @@ type CacheOptions = {
|
|
|
128
128
|
use_etags?: boolean;
|
|
129
129
|
headers?: Record<string, string>,
|
|
130
130
|
use_canary_reporting?: boolean;
|
|
131
|
+
enabled?: boolean;
|
|
131
132
|
};
|
|
132
133
|
|
|
133
134
|
type CacheEntry = {
|
|
@@ -154,6 +155,7 @@ export function cache_http(options?: CacheOptions) {
|
|
|
154
155
|
const use_etags = options?.use_etags ?? true;
|
|
155
156
|
const cache_headers = options?.headers ?? {};
|
|
156
157
|
const canary_report = options?.use_canary_reporting ?? false;
|
|
158
|
+
const enabled = options?.enabled ?? true;
|
|
157
159
|
|
|
158
160
|
const entries = new Map<string, CacheEntry>();
|
|
159
161
|
let total_cache_size = 0;
|
|
@@ -267,7 +269,8 @@ export function cache_http(options?: CacheOptions) {
|
|
|
267
269
|
cached_ts: now_ts
|
|
268
270
|
};
|
|
269
271
|
|
|
270
|
-
|
|
272
|
+
if (enabled)
|
|
273
|
+
store_cache_entry(file_path, entry, now_ts);
|
|
271
274
|
}
|
|
272
275
|
|
|
273
276
|
return build_response(entry, req, 200);
|
|
@@ -290,7 +293,8 @@ export function cache_http(options?: CacheOptions) {
|
|
|
290
293
|
cached_ts: now_ts
|
|
291
294
|
};
|
|
292
295
|
|
|
293
|
-
|
|
296
|
+
if (enabled)
|
|
297
|
+
store_cache_entry(cache_key, entry, now_ts);
|
|
294
298
|
}
|
|
295
299
|
|
|
296
300
|
return build_response(entry, req, status_code);
|