@hkdigital/lib-sveltekit 0.1.69 → 0.1.70

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.
@@ -26,4 +26,3 @@ export function getCachedResponse(cacheKeyParams: {
26
26
  url: string | URL;
27
27
  headers?: object;
28
28
  }): Promise<Response | import("./typedef").ResponseWithStale | null>;
29
- export const defaultCacheStorage: import("../../classes/cache").CacheStorage;
@@ -3,10 +3,20 @@ import {
3
3
  PersistentResponseCache
4
4
  } from '../../classes/cache';
5
5
 
6
- // Create the default cache storage
7
- export const defaultCacheStorage = createCacheStorage(
8
- process.env.NODE_ENV === 'test' ? 'memory' : 'persistent'
9
- );
6
+ let defaultCacheStorage = null;
7
+
8
+ function getCacheStorage()
9
+ {
10
+ if( !defaultCacheStorage )
11
+ {
12
+ defaultCacheStorage =
13
+ createCacheStorage(
14
+ process.env.NODE_ENV === 'test' ? 'memory' : 'persistent'
15
+ );
16
+ }
17
+
18
+ return defaultCacheStorage
19
+ }
10
20
 
11
21
  /**
12
22
  * Store a response in the cache
@@ -50,7 +60,7 @@ export async function storeResponseInCache(cacheKeyParams, response, metadata) {
50
60
  };
51
61
 
52
62
  // Store in cache
53
- await defaultCacheStorage.set(cacheKey, response, enhancedMetadata);
63
+ await getCacheStorage().set(cacheKey, response, enhancedMetadata);
54
64
  } catch (error) {
55
65
  console.error('Cache storage error:', error);
56
66
  }
@@ -75,7 +85,7 @@ export async function getCachedResponse(cacheKeyParams) {
75
85
  const cacheKey = generateCacheKey(url, headers);
76
86
 
77
87
  // Get cached entry
78
- const cachedEntry = await defaultCacheStorage.get(cacheKey);
88
+ const cachedEntry = await getCacheStorage().get(cacheKey);
79
89
 
80
90
  if (!cachedEntry) {
81
91
  return null;
@@ -169,6 +169,8 @@ export async function httpRequest(options) {
169
169
 
170
170
  const url = toURL(rawUrl);
171
171
 
172
+ console.debug(`httpRequest:load [${url.pathname}]`);
173
+
172
174
  // Only consider caching for GET requests
173
175
  const shouldAttemptCache = cacheEnabled && method === METHOD_GET;
174
176
 
@@ -178,9 +180,12 @@ export async function httpRequest(options) {
178
180
  const cachedResponse = await getCachedResponse(cacheKeyParams);
179
181
 
180
182
  if (cachedResponse) {
181
- console.debug(`Cache hit [${url.pathname}]`);
183
+ console.debug(`httpRequest:cache-hit [${url.pathname}]`);
182
184
  return cachedResponse;
183
185
  }
186
+ else {
187
+ console.debug(`httpRequest:cache-miss [${url.pathname}]`);
188
+ }
184
189
  }
185
190
 
186
191
  // @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
@@ -6,8 +6,8 @@
6
6
  getGameWidthOnPortrait
7
7
  } from './gamebox.util.js';
8
8
 
9
- //import { enableContainerScaling } from '../../util/design-system/index.js';
10
- import { enableContainerScaling } from '@hkdigital/lib-sveltekit/util/design-system/index.js';
9
+ import { enableContainerScaling } from '../../util/design-system/index.js';
10
+ // import { enableContainerScaling } from '@hkdigital/lib-sveltekit/util/design-system/index.js';
11
11
 
12
12
  /**
13
13
  * @typedef {{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.1.69",
3
+ "version": "0.1.70",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"