s3db.js 8.0.1 → 8.0.2
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/PLUGINS.md +114 -39
- package/README.md +1 -25
- package/dist/s3db.cjs.js +67 -23
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +67 -23
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +67 -23
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/plugins/cache/memory-cache.class.js +2 -2
- package/src/plugins/cache.plugin.js +75 -21
package/package.json
CHANGED
|
@@ -91,8 +91,8 @@ export class MemoryCache extends Cache {
|
|
|
91
91
|
super(config);
|
|
92
92
|
this.cache = {};
|
|
93
93
|
this.meta = {};
|
|
94
|
-
this.maxSize = config.maxSize
|
|
95
|
-
this.ttl = config.ttl
|
|
94
|
+
this.maxSize = config.maxSize !== undefined ? config.maxSize : 1000;
|
|
95
|
+
this.ttl = config.ttl !== undefined ? config.ttl : 300000;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async _set(key, data) {
|
|
@@ -11,14 +11,26 @@ import tryFn from "../concerns/try-fn.js";
|
|
|
11
11
|
export class CachePlugin extends Plugin {
|
|
12
12
|
constructor(options = {}) {
|
|
13
13
|
super(options);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
|
|
15
|
+
// Extract primary configuration
|
|
16
|
+
this.driverName = options.driver || 's3';
|
|
17
|
+
this.ttl = options.ttl;
|
|
18
|
+
this.maxSize = options.maxSize;
|
|
19
|
+
this.config = options.config || {};
|
|
20
|
+
|
|
21
|
+
// Plugin-level settings
|
|
22
|
+
this.includePartitions = options.includePartitions !== false;
|
|
23
|
+
this.partitionStrategy = options.partitionStrategy || 'hierarchical';
|
|
24
|
+
this.partitionAware = options.partitionAware !== false;
|
|
25
|
+
this.trackUsage = options.trackUsage !== false;
|
|
26
|
+
this.preloadRelated = options.preloadRelated !== false;
|
|
27
|
+
|
|
28
|
+
// Legacy support - keep the old options for backward compatibility
|
|
29
|
+
this.legacyConfig = {
|
|
30
|
+
memoryOptions: options.memoryOptions,
|
|
31
|
+
filesystemOptions: options.filesystemOptions,
|
|
32
|
+
s3Options: options.s3Options,
|
|
33
|
+
driver: options.driver
|
|
22
34
|
};
|
|
23
35
|
}
|
|
24
36
|
|
|
@@ -28,26 +40,68 @@ export class CachePlugin extends Plugin {
|
|
|
28
40
|
|
|
29
41
|
async onSetup() {
|
|
30
42
|
// Initialize cache driver
|
|
31
|
-
if (this.
|
|
43
|
+
if (this.driverName && typeof this.driverName === 'object') {
|
|
32
44
|
// Use custom driver instance if provided
|
|
33
|
-
this.driver = this.
|
|
34
|
-
} else if (this.
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
this.driver = this.driverName;
|
|
46
|
+
} else if (this.driverName === 'memory') {
|
|
47
|
+
// Build driver configuration with proper precedence
|
|
48
|
+
const driverConfig = {
|
|
49
|
+
...this.legacyConfig.memoryOptions, // Legacy support (lowest priority)
|
|
50
|
+
...this.config, // New config format (medium priority)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Add global settings if defined (highest priority)
|
|
54
|
+
if (this.ttl !== undefined) {
|
|
55
|
+
driverConfig.ttl = this.ttl;
|
|
56
|
+
}
|
|
57
|
+
if (this.maxSize !== undefined) {
|
|
58
|
+
driverConfig.maxSize = this.maxSize;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.driver = new MemoryCache(driverConfig);
|
|
62
|
+
} else if (this.driverName === 'filesystem') {
|
|
63
|
+
// Build driver configuration with proper precedence
|
|
64
|
+
const driverConfig = {
|
|
65
|
+
...this.legacyConfig.filesystemOptions, // Legacy support (lowest priority)
|
|
66
|
+
...this.config, // New config format (medium priority)
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Add global settings if defined (highest priority)
|
|
70
|
+
if (this.ttl !== undefined) {
|
|
71
|
+
driverConfig.ttl = this.ttl;
|
|
72
|
+
}
|
|
73
|
+
if (this.maxSize !== undefined) {
|
|
74
|
+
driverConfig.maxSize = this.maxSize;
|
|
75
|
+
}
|
|
76
|
+
|
|
37
77
|
// Use partition-aware filesystem cache if enabled
|
|
38
|
-
if (this.
|
|
78
|
+
if (this.partitionAware) {
|
|
39
79
|
this.driver = new PartitionAwareFilesystemCache({
|
|
40
|
-
partitionStrategy: this.
|
|
41
|
-
trackUsage: this.
|
|
42
|
-
preloadRelated: this.
|
|
43
|
-
...
|
|
80
|
+
partitionStrategy: this.partitionStrategy,
|
|
81
|
+
trackUsage: this.trackUsage,
|
|
82
|
+
preloadRelated: this.preloadRelated,
|
|
83
|
+
...driverConfig
|
|
44
84
|
});
|
|
45
85
|
} else {
|
|
46
|
-
this.driver = new FilesystemCache(
|
|
86
|
+
this.driver = new FilesystemCache(driverConfig);
|
|
47
87
|
}
|
|
48
88
|
} else {
|
|
49
|
-
// Default to S3Cache
|
|
50
|
-
|
|
89
|
+
// Default to S3Cache - build driver configuration with proper precedence
|
|
90
|
+
const driverConfig = {
|
|
91
|
+
client: this.database.client, // Required for S3Cache
|
|
92
|
+
...this.legacyConfig.s3Options, // Legacy support (lowest priority)
|
|
93
|
+
...this.config, // New config format (medium priority)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Add global settings if defined (highest priority)
|
|
97
|
+
if (this.ttl !== undefined) {
|
|
98
|
+
driverConfig.ttl = this.ttl;
|
|
99
|
+
}
|
|
100
|
+
if (this.maxSize !== undefined) {
|
|
101
|
+
driverConfig.maxSize = this.maxSize;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.driver = new S3Cache(driverConfig);
|
|
51
105
|
}
|
|
52
106
|
|
|
53
107
|
// Use database hooks instead of method overwriting
|