@dnax/core 0.8.18 → 0.8.20
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/app/hono.ts +21 -2
- package/lib/bento/index.ts +30 -0
- package/package.json +2 -1
- package/types/index.ts +3 -0
package/app/hono.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { useRest } from "../driver/mongo/rest";
|
|
|
14
14
|
import moment from "moment";
|
|
15
15
|
import { Cfg } from "../config";
|
|
16
16
|
import { getService } from "../lib/service";
|
|
17
|
+
import { bentoCache, bentoKey } from "../lib/bento";
|
|
17
18
|
import { MediaDrive } from "../lib/media";
|
|
18
19
|
import { isStudio } from "../lib/studio";
|
|
19
20
|
import { pick } from "radash";
|
|
@@ -23,8 +24,8 @@ import { checkPermission, getPermission } from "../lib/permissions";
|
|
|
23
24
|
import { ipRestriction } from "hono/ip-restriction";
|
|
24
25
|
import { logger } from "hono/logger";
|
|
25
26
|
import { v4 } from "uuid";
|
|
27
|
+
const cache = bentoCache.namespace("DNAX_API");
|
|
26
28
|
const app = new Hono();
|
|
27
|
-
|
|
28
29
|
const API_PATH = "/api";
|
|
29
30
|
function HonoInstance(): typeof app {
|
|
30
31
|
if (Cfg?.server?.logger) {
|
|
@@ -430,7 +431,25 @@ function HonoInstance(): typeof app {
|
|
|
430
431
|
// udpateOne
|
|
431
432
|
|
|
432
433
|
if (action == "find") {
|
|
433
|
-
|
|
434
|
+
let keyCache = bentoKey({
|
|
435
|
+
data: body,
|
|
436
|
+
query: c.req.query,
|
|
437
|
+
});
|
|
438
|
+
if (useCache) {
|
|
439
|
+
let responseFromCache = await cache.get(keyCache);
|
|
440
|
+
if (responseFromCache) {
|
|
441
|
+
response = responseFromCache;
|
|
442
|
+
} else {
|
|
443
|
+
response = await rest.find(collection, body?.params || {});
|
|
444
|
+
await cache.set({
|
|
445
|
+
key: keyCache,
|
|
446
|
+
value: response,
|
|
447
|
+
ttl: col?.cache?.ttl || "1m",
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
response = await rest.find(collection, body?.params || {});
|
|
452
|
+
}
|
|
434
453
|
}
|
|
435
454
|
if (action == "findOne") {
|
|
436
455
|
response = await rest.findOne(
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BentoCache, bentostore } from "bentocache";
|
|
2
|
+
import { memoryDriver } from "bentocache/drivers/memory";
|
|
3
|
+
const bentoCache = new BentoCache({
|
|
4
|
+
default: "dnaxCache",
|
|
5
|
+
stores: {
|
|
6
|
+
dnaxCache: bentostore().useL1Layer(
|
|
7
|
+
memoryDriver({
|
|
8
|
+
maxSize: 100 * 1024 * 1024,
|
|
9
|
+
})
|
|
10
|
+
),
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function bentoKey(data: object | string) {
|
|
15
|
+
let key = "";
|
|
16
|
+
if (data) {
|
|
17
|
+
if (typeof data == "object") {
|
|
18
|
+
key = JSON.stringify(data);
|
|
19
|
+
key = key.replace(/\s/g, "").trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (typeof data == "string") {
|
|
23
|
+
key = data.replace(/\s/g, "").trim();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return key;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { bentoCache, bentoKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.20",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@lukeed/ms": "^2.0.2",
|
|
21
21
|
"@orama/orama": "^2.0.23",
|
|
22
22
|
"@types/jsonwebtoken": "^9.0.6",
|
|
23
|
+
"bentocache": "^1.0.0-beta.9",
|
|
23
24
|
"boxen": "^7.1.1",
|
|
24
25
|
"chokidar": "^3.6.0",
|
|
25
26
|
"clean-deep": "^3.4.0",
|
package/types/index.ts
CHANGED