Skip to content

Commit 453d8a5

Browse files
committed
caching layer persistent
1 parent e743df0 commit 453d8a5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/core/src/containers/modules/dataSource.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
import { Profile } from '../../models/profile';
99
import { ClassType } from '../../lib/utils/module';
1010
import { ConfigurationError } from '@vulcan-sql/core/utils';
11-
import { ICacheLayerOptions, cacheProfileName } from '@vulcan-sql/core/models';
11+
import {
12+
ICacheLayerOptions,
13+
cacheLayerPersistentFileName,
14+
cacheProfileName,
15+
} from '@vulcan-sql/core/models';
1216
import 'reflect-metadata';
1317

1418
export const dataSourceModule = (
@@ -26,6 +30,7 @@ export const dataSourceModule = (
2630
type: options.loader!.toLocaleLowerCase(),
2731
// allow '*' to make every user request could use the cache-layer data source.
2832
allow: '*',
33+
connection: { ['persistent-path']: cacheLayerPersistentFileName },
2934
} as Profile);
3035
}
3136

packages/core/src/models/cacheLayerOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface ICacheLayerOptions {
1919
// The cache layer profile name is used to load the cache data to table name from cache files
2020
export const cacheProfileName = 'vulcan.cache';
2121

22+
// The cache layer persistent file name, if the file name is set to ":memory:", it will use in-memory database
23+
export const cacheLayerPersistentFileName =
24+
process.env['VULCAN_CACHE_LAYER_PERSISTENT_FILE_NAME'] ||
25+
'vulcan_caching_layer.db';
26+
2227
// The schema name for vulcan used to create table when loading cache files to cache data source
2328
export const vulcanCacheSchemaName = 'vulcan';
2429

packages/core/test/containers/cacheLayer.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CacheLayerLoader,
33
cacheLayerModule,
4+
cacheLayerPersistentFileName,
45
CacheLayerStoreFormatType,
56
cacheProfileName,
67
DataResult,
@@ -89,11 +90,21 @@ it('Cache layer module should add "vulcan.cache" profile and bind "duckdb" type
8990

9091
expect(dsFromTestDuck.injectedProfiles).toEqual([
9192
{ name: 'test-duck', type: 'duckdb', allow: '*' },
92-
{ name: cacheProfileName, type: 'duckdb', allow: '*' },
93+
{
94+
name: cacheProfileName,
95+
type: 'duckdb',
96+
allow: '*',
97+
connection: { ['persistent-path']: cacheLayerPersistentFileName },
98+
},
9399
]);
94100
expect(dsFromCacheLayer.injectedProfiles).toEqual([
95101
{ name: 'test-duck', type: 'duckdb', allow: '*' },
96-
{ name: cacheProfileName, type: 'duckdb', allow: '*' },
102+
{
103+
name: cacheProfileName,
104+
type: 'duckdb',
105+
allow: '*',
106+
connection: { ['persistent-path']: cacheLayerPersistentFileName },
107+
},
97108
]);
98109
});
99110

0 commit comments

Comments
 (0)