rwsdk 0.2.0-alpha.6-test.20250806100800 → 0.2.0-alpha.6-test.20250806102744
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.
|
@@ -11,35 +11,17 @@ const createDurableObjectDb = (durableObjectBinding, name = "main") => {
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
export function createDb(durableObjectBinding, name = "main") {
|
|
14
|
-
const cacheKey = `${durableObjectBinding.toString()}_${name}`;
|
|
15
14
|
const getDb = () => {
|
|
16
|
-
|
|
15
|
+
let db = moduleLevelDbCache.get(name);
|
|
16
|
+
if (!db) {
|
|
17
|
+
db = createDurableObjectDb(durableObjectBinding, name);
|
|
18
|
+
moduleLevelDbCache.set(name, db);
|
|
19
|
+
}
|
|
17
20
|
if (requestInfo.rw) {
|
|
18
21
|
if (!requestInfo.rw.databases) {
|
|
19
22
|
requestInfo.rw.databases = new Map();
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
// db is in requestInfo cache
|
|
23
|
-
if (db) {
|
|
24
|
-
return db;
|
|
25
|
-
}
|
|
26
|
-
// db is in module-level cache
|
|
27
|
-
const moduleDb = moduleLevelDbCache.get(cacheKey);
|
|
28
|
-
if (moduleDb) {
|
|
29
|
-
requestInfo.rw.databases.set(cacheKey, moduleDb);
|
|
30
|
-
moduleLevelDbCache.delete(cacheKey);
|
|
31
|
-
return moduleDb;
|
|
32
|
-
}
|
|
33
|
-
// db is not in any cache
|
|
34
|
-
db = createDurableObjectDb(durableObjectBinding, name);
|
|
35
|
-
requestInfo.rw.databases.set(cacheKey, db);
|
|
36
|
-
return db;
|
|
37
|
-
}
|
|
38
|
-
// requestInfo is not available, use module-level cache
|
|
39
|
-
let db = moduleLevelDbCache.get(cacheKey);
|
|
40
|
-
if (!db) {
|
|
41
|
-
db = createDurableObjectDb(durableObjectBinding, name);
|
|
42
|
-
moduleLevelDbCache.set(cacheKey, db);
|
|
24
|
+
requestInfo.rw.databases.set(name, db);
|
|
43
25
|
}
|
|
44
26
|
return db;
|
|
45
27
|
};
|
package/package.json
CHANGED