graphile-cache 3.11.1 → 3.12.0
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/esm/graphile-cache.js +5 -2
- package/esm/index.js +2 -0
- package/esm/module-config-cache.js +47 -0
- package/graphile-cache.d.ts +4 -1
- package/graphile-cache.js +5 -2
- package/index.d.ts +1 -0
- package/index.js +4 -1
- package/module-config-cache.d.ts +32 -0
- package/module-config-cache.js +51 -0
- package/package.json +5 -5
package/esm/graphile-cache.js
CHANGED
|
@@ -21,16 +21,19 @@ export const cacheEvents = new CacheEventEmitter();
|
|
|
21
21
|
* Get cache configuration from environment variables
|
|
22
22
|
*
|
|
23
23
|
* Supports:
|
|
24
|
-
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default:
|
|
24
|
+
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default: 50)
|
|
25
25
|
* - GRAPHILE_CACHE_TTL_MS: TTL in milliseconds
|
|
26
26
|
* - Production default: ONE_YEAR
|
|
27
27
|
* - Development default: FIVE_MINUTES_MS
|
|
28
|
+
*
|
|
29
|
+
* NOTE: This value should be <= PG_CACHE_MAX (also default: 50) so that
|
|
30
|
+
* every cached PostGraphile instance has a live pool backing it.
|
|
28
31
|
*/
|
|
29
32
|
export function getCacheConfig() {
|
|
30
33
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
31
34
|
const max = process.env.GRAPHILE_CACHE_MAX
|
|
32
35
|
? parseInt(process.env.GRAPHILE_CACHE_MAX, 10)
|
|
33
|
-
:
|
|
36
|
+
: 50;
|
|
34
37
|
const ttl = process.env.GRAPHILE_CACHE_TTL_MS
|
|
35
38
|
? parseInt(process.env.GRAPHILE_CACHE_TTL_MS, 10)
|
|
36
39
|
: isDevelopment
|
package/esm/index.js
CHANGED
|
@@ -10,3 +10,5 @@ CacheEventEmitter, cacheEvents, getCacheConfig, getCacheStats,
|
|
|
10
10
|
clearMatchingEntries } from './graphile-cache';
|
|
11
11
|
// Factory for creating PostGraphile v5 instances
|
|
12
12
|
export { createGraphileInstance } from './create-instance';
|
|
13
|
+
// Generic module config cache for plugin lookups
|
|
14
|
+
export { ModuleConfigCache } from './module-config-cache';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModuleConfigCache — generic LRU cache for module config lookups
|
|
3
|
+
*
|
|
4
|
+
* Provides a bounded, TTL-based cache for runtime config discovery
|
|
5
|
+
* (billing config, agent discovery, inference log info, etc.).
|
|
6
|
+
*
|
|
7
|
+
* Wraps lru-cache with:
|
|
8
|
+
* - LRU eviction (bounded memory)
|
|
9
|
+
* - TTL-based expiry
|
|
10
|
+
* - Named logging for debugging
|
|
11
|
+
* - clear() hook for future LISTEN/NOTIFY invalidation
|
|
12
|
+
*/
|
|
13
|
+
import { LRUCache } from 'lru-cache';
|
|
14
|
+
import { Logger } from '@pgpmjs/logger';
|
|
15
|
+
export class ModuleConfigCache {
|
|
16
|
+
cache;
|
|
17
|
+
log;
|
|
18
|
+
name;
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
this.name = opts.name;
|
|
21
|
+
this.log = new Logger(`cache:${opts.name}`);
|
|
22
|
+
this.cache = new LRUCache({
|
|
23
|
+
max: opts.max ?? 100,
|
|
24
|
+
ttl: opts.ttlMs ?? 60_000,
|
|
25
|
+
updateAgeOnGet: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
get(key) {
|
|
29
|
+
return this.cache.get(key);
|
|
30
|
+
}
|
|
31
|
+
set(key, value) {
|
|
32
|
+
this.cache.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
delete(key) {
|
|
35
|
+
return this.cache.delete(key);
|
|
36
|
+
}
|
|
37
|
+
clear() {
|
|
38
|
+
this.log.debug(`Clearing all entries (size=${this.cache.size})`);
|
|
39
|
+
this.cache.clear();
|
|
40
|
+
}
|
|
41
|
+
get size() {
|
|
42
|
+
return this.cache.size;
|
|
43
|
+
}
|
|
44
|
+
has(key) {
|
|
45
|
+
return this.cache.has(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/graphile-cache.d.ts
CHANGED
|
@@ -25,10 +25,13 @@ export interface CacheConfig {
|
|
|
25
25
|
* Get cache configuration from environment variables
|
|
26
26
|
*
|
|
27
27
|
* Supports:
|
|
28
|
-
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default:
|
|
28
|
+
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default: 50)
|
|
29
29
|
* - GRAPHILE_CACHE_TTL_MS: TTL in milliseconds
|
|
30
30
|
* - Production default: ONE_YEAR
|
|
31
31
|
* - Development default: FIVE_MINUTES_MS
|
|
32
|
+
*
|
|
33
|
+
* NOTE: This value should be <= PG_CACHE_MAX (also default: 50) so that
|
|
34
|
+
* every cached PostGraphile instance has a live pool backing it.
|
|
32
35
|
*/
|
|
33
36
|
export declare function getCacheConfig(): CacheConfig;
|
|
34
37
|
/**
|
package/graphile-cache.js
CHANGED
|
@@ -28,16 +28,19 @@ exports.cacheEvents = new CacheEventEmitter();
|
|
|
28
28
|
* Get cache configuration from environment variables
|
|
29
29
|
*
|
|
30
30
|
* Supports:
|
|
31
|
-
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default:
|
|
31
|
+
* - GRAPHILE_CACHE_MAX: Maximum number of entries (default: 50)
|
|
32
32
|
* - GRAPHILE_CACHE_TTL_MS: TTL in milliseconds
|
|
33
33
|
* - Production default: ONE_YEAR
|
|
34
34
|
* - Development default: FIVE_MINUTES_MS
|
|
35
|
+
*
|
|
36
|
+
* NOTE: This value should be <= PG_CACHE_MAX (also default: 50) so that
|
|
37
|
+
* every cached PostGraphile instance has a live pool backing it.
|
|
35
38
|
*/
|
|
36
39
|
function getCacheConfig() {
|
|
37
40
|
const isDevelopment = process.env.NODE_ENV === 'development';
|
|
38
41
|
const max = process.env.GRAPHILE_CACHE_MAX
|
|
39
42
|
? parseInt(process.env.GRAPHILE_CACHE_MAX, 10)
|
|
40
|
-
:
|
|
43
|
+
: 50;
|
|
41
44
|
const ttl = process.env.GRAPHILE_CACHE_TTL_MS
|
|
42
45
|
? parseInt(process.env.GRAPHILE_CACHE_TTL_MS, 10)
|
|
43
46
|
: isDevelopment
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { graphileCache, GraphileCacheEntry, closeAllCaches, ONE_HOUR_MS, FIVE_MINUTES_MS, EvictionReason, CacheEventEmitter, CacheEvictionEvent, cacheEvents, CacheConfig, getCacheConfig, CacheStats, getCacheStats, clearMatchingEntries } from './graphile-cache';
|
|
2
2
|
export { createGraphileInstance } from './create-instance';
|
|
3
|
+
export { ModuleConfigCache, ModuleConfigCacheOptions } from './module-config-cache';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGraphileInstance = exports.clearMatchingEntries = exports.getCacheStats = exports.getCacheConfig = exports.cacheEvents = exports.CacheEventEmitter = exports.FIVE_MINUTES_MS = exports.ONE_HOUR_MS = exports.closeAllCaches = exports.graphileCache = void 0;
|
|
3
|
+
exports.ModuleConfigCache = exports.createGraphileInstance = exports.clearMatchingEntries = exports.getCacheStats = exports.getCacheConfig = exports.cacheEvents = exports.CacheEventEmitter = exports.FIVE_MINUTES_MS = exports.ONE_HOUR_MS = exports.closeAllCaches = exports.graphileCache = void 0;
|
|
4
4
|
// Main exports from graphile-cache package
|
|
5
5
|
var graphile_cache_1 = require("./graphile-cache");
|
|
6
6
|
// Cache instance and entry type
|
|
@@ -19,3 +19,6 @@ Object.defineProperty(exports, "clearMatchingEntries", { enumerable: true, get:
|
|
|
19
19
|
// Factory for creating PostGraphile v5 instances
|
|
20
20
|
var create_instance_1 = require("./create-instance");
|
|
21
21
|
Object.defineProperty(exports, "createGraphileInstance", { enumerable: true, get: function () { return create_instance_1.createGraphileInstance; } });
|
|
22
|
+
// Generic module config cache for plugin lookups
|
|
23
|
+
var module_config_cache_1 = require("./module-config-cache");
|
|
24
|
+
Object.defineProperty(exports, "ModuleConfigCache", { enumerable: true, get: function () { return module_config_cache_1.ModuleConfigCache; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModuleConfigCache — generic LRU cache for module config lookups
|
|
3
|
+
*
|
|
4
|
+
* Provides a bounded, TTL-based cache for runtime config discovery
|
|
5
|
+
* (billing config, agent discovery, inference log info, etc.).
|
|
6
|
+
*
|
|
7
|
+
* Wraps lru-cache with:
|
|
8
|
+
* - LRU eviction (bounded memory)
|
|
9
|
+
* - TTL-based expiry
|
|
10
|
+
* - Named logging for debugging
|
|
11
|
+
* - clear() hook for future LISTEN/NOTIFY invalidation
|
|
12
|
+
*/
|
|
13
|
+
export interface ModuleConfigCacheOptions {
|
|
14
|
+
/** Cache name (used in log prefix) */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Max entries before LRU eviction (default: 100) */
|
|
17
|
+
max?: number;
|
|
18
|
+
/** TTL in milliseconds (default: 60_000) */
|
|
19
|
+
ttlMs?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class ModuleConfigCache<T> {
|
|
22
|
+
private cache;
|
|
23
|
+
private log;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
constructor(opts: ModuleConfigCacheOptions);
|
|
26
|
+
get(key: string): T | undefined;
|
|
27
|
+
set(key: string, value: T): void;
|
|
28
|
+
delete(key: string): boolean;
|
|
29
|
+
clear(): void;
|
|
30
|
+
get size(): number;
|
|
31
|
+
has(key: string): boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ModuleConfigCache — generic LRU cache for module config lookups
|
|
4
|
+
*
|
|
5
|
+
* Provides a bounded, TTL-based cache for runtime config discovery
|
|
6
|
+
* (billing config, agent discovery, inference log info, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Wraps lru-cache with:
|
|
9
|
+
* - LRU eviction (bounded memory)
|
|
10
|
+
* - TTL-based expiry
|
|
11
|
+
* - Named logging for debugging
|
|
12
|
+
* - clear() hook for future LISTEN/NOTIFY invalidation
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ModuleConfigCache = void 0;
|
|
16
|
+
const lru_cache_1 = require("lru-cache");
|
|
17
|
+
const logger_1 = require("@pgpmjs/logger");
|
|
18
|
+
class ModuleConfigCache {
|
|
19
|
+
cache;
|
|
20
|
+
log;
|
|
21
|
+
name;
|
|
22
|
+
constructor(opts) {
|
|
23
|
+
this.name = opts.name;
|
|
24
|
+
this.log = new logger_1.Logger(`cache:${opts.name}`);
|
|
25
|
+
this.cache = new lru_cache_1.LRUCache({
|
|
26
|
+
max: opts.max ?? 100,
|
|
27
|
+
ttl: opts.ttlMs ?? 60_000,
|
|
28
|
+
updateAgeOnGet: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
get(key) {
|
|
32
|
+
return this.cache.get(key);
|
|
33
|
+
}
|
|
34
|
+
set(key, value) {
|
|
35
|
+
this.cache.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
delete(key) {
|
|
38
|
+
return this.cache.delete(key);
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this.log.debug(`Clearing all entries (size=${this.cache.size})`);
|
|
42
|
+
this.cache.clear();
|
|
43
|
+
}
|
|
44
|
+
get size() {
|
|
45
|
+
return this.cache.size;
|
|
46
|
+
}
|
|
47
|
+
has(key) {
|
|
48
|
+
return this.cache.has(key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ModuleConfigCache = ModuleConfigCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-cache",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostGraphile v5 LRU cache with automatic pool cleanup integration",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"@pgpmjs/logger": "^2.11.0",
|
|
33
33
|
"express": "^5.2.1",
|
|
34
34
|
"grafserv": "1.0.0",
|
|
35
|
-
"graphile-realtime-subscriptions": "^0.7.
|
|
35
|
+
"graphile-realtime-subscriptions": "^0.7.1",
|
|
36
36
|
"lru-cache": "^11.2.7",
|
|
37
|
-
"pg-cache": "^3.
|
|
38
|
-
"postgraphile": "5.0.
|
|
37
|
+
"pg-cache": "^3.11.0",
|
|
38
|
+
"postgraphile": "5.0.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/express": "^5.0.6",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"constructive",
|
|
53
53
|
"v5"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c0d04574f7719d92e67becb58d60791ae978c5f5"
|
|
56
56
|
}
|