Function
writeModuleToCache
(
moduleURI: string,
moduleContent: string,
lix: Lix
)
Source from the content-addressed store, hash-verified
| 34 | } |
| 35 | |
| 36 | async function writeModuleToCache( |
| 37 | moduleURI: string, |
| 38 | moduleContent: string, |
| 39 | lix: Lix |
| 40 | ): Promise<void> { |
| 41 | const moduleHash = escape(moduleURI); |
| 42 | const filePath = `/cache/plugins/${moduleHash}`; |
| 43 | |
| 44 | await lix.db |
| 45 | .insertInto("file") |
| 46 | .values({ |
| 47 | path: filePath, |
| 48 | data: new TextEncoder().encode(moduleContent), |
| 49 | }) |
| 50 | // update the cache |
| 51 | .onConflict((oc) => |
| 52 | oc.doUpdateSet({ data: new TextEncoder().encode(moduleContent) }) |
| 53 | ) |
| 54 | .execute(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Implements a "Network-First" caching strategy. |
Tested by
no test coverage detected