miolo 3.0.0-beta.196 → 3.0.0-beta.198

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miolo",
3
- "version": "3.0.0-beta.196",
3
+ "version": "3.0.0-beta.198",
4
4
  "description": "all-in-one koa-based server",
5
5
  "author": "Donato Lorenzo <donato@afialapis.com>",
6
6
  "contributors": [
@@ -1,35 +1,62 @@
1
1
  import { cacheiro } from "cacheiro"
2
- import { miolo_cacher_options_for_custom } from "./options.mjs"
2
+ import { miolo_cacher_options_for_custom, miolo_cacher_options_for_fly } from "./options.mjs"
3
3
 
4
- let _glob_cache_stores = {}
4
+ let _glob_cache_mother
5
+ const _local_cache_instances = new Map()
6
+
7
+ const _get_cache_mother = async (config, logger) => {
8
+ if (_glob_cache_mother === undefined) {
9
+ const default_options = miolo_cacher_options_for_fly(
10
+ config,
11
+ {
12
+ type: process.env.MIOLO_CACHE_TYPE || "combined",
13
+ namespace: "miolo-cache-mother"
14
+ },
15
+ logger
16
+ )
17
+
18
+ _glob_cache_mother = await cacheiro(default_options)
19
+ }
20
+ return _glob_cache_mother
21
+ }
5
22
 
6
23
  export function init_context_cache(config, logger) {
7
24
  const custom_options = miolo_cacher_options_for_custom(config, logger)
8
25
 
9
- const _init_cache = async (name) => {
10
- const cache_store = await cacheiro(custom_options?.[name] || {})
11
- _glob_cache_stores[name] = cache_store
12
- return cache_store
26
+ const _init_cache_instance = async (name) => {
27
+ const cache_mother = await _get_cache_mother(config, logger)
28
+
29
+ const cache_instance = await cacheiro(custom_options?.[name] || {})
30
+ await cache_mother.setItem(name, "1")
31
+ _local_cache_instances.set(name, cache_instance)
32
+ return cache_instance
13
33
  }
14
34
 
15
35
  const init = async () => {
16
- _glob_cache_stores = {}
17
-
18
- for (const name of Object.keys(custom_options)) {
19
- _glob_cache_stores[name] = await _init_cache(name)
20
- }
36
+ await _get_cache_mother(config, logger)
21
37
  }
22
38
 
23
39
  const get_cache = async (name) => {
24
- let cache_store = _glob_cache_stores?.[name]
25
- if (!cache_store) {
26
- cache_store = await _init_cache(name)
40
+ if (_local_cache_instances.has(name)) {
41
+ return _local_cache_instances.get(name)
27
42
  }
28
- return cache_store
43
+
44
+ const cache_mother = await _get_cache_mother(config, logger)
45
+
46
+ const exists_in_mother = await cache_mother.getItem(name)
47
+ if (exists_in_mother) {
48
+ const cache_instance = await cacheiro(custom_options?.[name] || {})
49
+ _local_cache_instances.set(name, cache_instance)
50
+ return cache_instance
51
+ }
52
+
53
+ return await _init_cache_instance(name)
29
54
  }
30
55
 
31
- const get_cache_names = async () => {
32
- return Object.keys(_glob_cache_stores)
56
+ const get_cache_names = async (pattern = "*") => {
57
+ const cache_mother = await _get_cache_mother(config, logger)
58
+
59
+ return await cache_mother.getKeys(pattern)
33
60
  }
34
61
 
35
62
  const drop_cache = async (name, clean = true) => {
@@ -43,12 +70,17 @@ export function init_context_cache(config, logger) {
43
70
  }
44
71
  }
45
72
  }
46
- delete _glob_cache_stores[name]
73
+ _local_cache_instances.delete(name)
74
+
75
+ const cache_mother = await _get_cache_mother(config, logger)
76
+ await cache_mother.unsetItem(name)
47
77
  }
48
78
 
49
79
  const close = async (clean = true) => {
80
+ const cache_mother = await _get_cache_mother(config, logger)
81
+
50
82
  if (clean) {
51
- for (const [_name, cache] of Object.entries(_glob_cache_stores)) {
83
+ for (const cache of _local_cache_instances.values()) {
52
84
  try {
53
85
  await cache.close()
54
86
  } catch (error) {
@@ -56,8 +88,10 @@ export function init_context_cache(config, logger) {
56
88
  }
57
89
  }
58
90
  }
91
+ _local_cache_instances.clear()
59
92
 
60
- _glob_cache_stores = {}
93
+ await cache_mother.close()
94
+ _glob_cache_mother = undefined
61
95
  }
62
96
 
63
97
  const cache_ctx = {
@@ -27,6 +27,12 @@ function _miolo_cacher_options_merge(def, opt, logger) {
27
27
  }
28
28
  }
29
29
 
30
+ export function miolo_cacher_options_for_fly(config, options, logger) {
31
+ const d = config.cache.default
32
+
33
+ return _miolo_cacher_options_merge(d, options, logger)
34
+ }
35
+
30
36
  export function miolo_cacher_options_for_calustra(config, logger) {
31
37
  const d = config.cache.default
32
38
  const c = config.cache.calustra
@@ -45,9 +45,9 @@
45
45
  "intre": "^3.0.0-beta.4",
46
46
  "joi": "^18.2.1",
47
47
  "lucide-react": "^1.16.0",
48
- "miolo-cli": "^3.0.0-beta.196",
48
+ "miolo-cli": "^3.0.0-beta.198",
49
49
  "miolo-model": "file:../miolo-model",
50
- "miolo-react": "^3.0.0-beta.196",
50
+ "miolo-react": "^3.0.0-beta.198",
51
51
  "next-themes": "^0.4.6",
52
52
  "radix-ui": "^1.4.3",
53
53
  "react": "^19.2.6",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "devDependencies": {
64
64
  "@biomejs/biome": "2.4.15",
65
- "miolo": "^3.0.0-beta.196",
65
+ "miolo": "^3.0.0-beta.198",
66
66
  "sass-embedded": "^1.99.0"
67
67
  },
68
68
  "overrides": {