-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacheEntrySet.mjs
30 lines (24 loc) · 868 Bytes
/
cacheEntrySet.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @ts-check
import Cache from "./Cache.mjs";
/** @typedef {import("./Cache.mjs").CacheEventMap} CacheEventMap */
/**
* Sets a {@link Cache.store cache store} entry, dispatching the
* {@linkcode Cache} event {@link CacheEventMap.set `set`}.
* @param {Cache} cache Cache to update.
* @param {import("./Cache.mjs").CacheKey} cacheKey Cache key.
* @param {import("./Cache.mjs").CacheValue} cacheValue Cache value.
*/
export default function cacheEntrySet(cache, cacheKey, cacheValue) {
if (!(cache instanceof Cache))
throw new TypeError("Argument 1 `cache` must be a `Cache` instance.");
if (typeof cacheKey !== "string")
throw new TypeError("Argument 2 `cacheKey` must be a string.");
cache.store[cacheKey] = cacheValue;
cache.dispatchEvent(
new CustomEvent(`${cacheKey}/set`, {
detail: {
cacheValue,
},
})
);
}