@dnax/core 0.73.9 → 0.74.1

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.
Files changed (2) hide show
  1. package/lib/bento/index.ts +25 -9
  2. package/package.json +1 -1
@@ -1,29 +1,32 @@
1
1
  import { BentoCache, bentostore } from "bentocache";
2
2
  import { memoryDriver } from "bentocache/drivers/memory";
3
3
  import { fileDriver } from "bentocache/drivers/file";
4
+
4
5
  import { useKey } from "../../utils";
5
6
  import { v4 } from "uuid";
6
7
  import fs from "fs-extra";
7
8
  import path from "path";
8
- const cacheDirectory = path.join(process.cwd(), "/.cache/system/");
9
- const cacheDirectoryData = path.join(process.cwd(), "/.cache/data/");
9
+ const BENTO_CACHE_DIR = "cache";
10
+ const cacheDirectory = path.join(process.cwd(), ".cache", "system");
11
+ const cacheDirectoryData = path.join(process.cwd(), ".cache", "data");
10
12
 
11
- if (!fs?.existsSync(path.resolve(cacheDirectory + "bentocache"))) {
12
- fs.mkdirSync(cacheDirectory + "bentocache", {
13
+ if (!fs?.existsSync(path.resolve(cacheDirectory))) {
14
+ fs.mkdirSync(cacheDirectory, {
13
15
  recursive: true,
14
16
  });
15
17
  }
16
18
 
17
- if (!fs?.existsSync(path.resolve(cacheDirectoryData + "bentocache"))) {
18
- fs.mkdirSync(cacheDirectoryData + "bentocache", {
19
+ if (!fs?.existsSync(path.resolve(cacheDirectoryData))) {
20
+ fs.mkdirSync(cacheDirectoryData, {
19
21
  recursive: true,
20
22
  });
21
23
  }
22
24
 
23
25
  function useCache(
24
- driver: "memory" = "memory",
26
+ driver: "memory" | "filesystem" = "memory",
25
27
  options: {
26
28
  maxSize?: string;
29
+ prefix?: string | undefined;
27
30
  } = {
28
31
  /**
29
32
  * @default 200mb
@@ -32,13 +35,26 @@ function useCache(
32
35
  }
33
36
  ): InstanceType<typeof BentoCache> {
34
37
  const bento = new BentoCache({
35
- default: "dataCache",
38
+ default: "memory",
36
39
  stores: {
37
- dataCache: bentostore().useL1Layer(
40
+ memory: bentostore().useL1Layer(
38
41
  memoryDriver({
39
42
  maxSize: options?.maxSize || "200mb",
40
43
  })
41
44
  ),
45
+ filesystem: bentostore()
46
+ .useL1Layer(
47
+ memoryDriver({
48
+ maxSize: options?.maxSize || "100mb",
49
+ prefix: options?.prefix || undefined,
50
+ })
51
+ )
52
+ .useL2Layer(
53
+ fileDriver({
54
+ directory: path.resolve(cacheDirectoryData),
55
+ prefix: options?.prefix || undefined,
56
+ })
57
+ ),
42
58
  },
43
59
  });
44
60
  return bento;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.73.9",
3
+ "version": "0.74.1",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},