Skip to content

Commit

Permalink
caching layer persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyjackfrost committed Aug 18, 2023
1 parent e743df0 commit 453d8a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/containers/modules/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { Profile } from '../../models/profile';
import { ClassType } from '../../lib/utils/module';
import { ConfigurationError } from '@vulcan-sql/core/utils';
import { ICacheLayerOptions, cacheProfileName } from '@vulcan-sql/core/models';
import {
ICacheLayerOptions,
cacheLayerPersistentFileName,
cacheProfileName,
} from '@vulcan-sql/core/models';
import 'reflect-metadata';

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

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/models/cacheLayerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface ICacheLayerOptions {
// The cache layer profile name is used to load the cache data to table name from cache files
export const cacheProfileName = 'vulcan.cache';

// The cache layer persistent file name, if the file name is set to ":memory:", it will use in-memory database
export const cacheLayerPersistentFileName =
process.env['VULCAN_CACHE_LAYER_PERSISTENT_FILE_NAME'] ||
'vulcan_caching_layer.db';

// The schema name for vulcan used to create table when loading cache files to cache data source
export const vulcanCacheSchemaName = 'vulcan';

Expand Down
15 changes: 13 additions & 2 deletions packages/core/test/containers/cacheLayer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CacheLayerLoader,
cacheLayerModule,
cacheLayerPersistentFileName,
CacheLayerStoreFormatType,
cacheProfileName,
DataResult,
Expand Down Expand Up @@ -89,11 +90,21 @@ it('Cache layer module should add "vulcan.cache" profile and bind "duckdb" type

expect(dsFromTestDuck.injectedProfiles).toEqual([
{ name: 'test-duck', type: 'duckdb', allow: '*' },
{ name: cacheProfileName, type: 'duckdb', allow: '*' },
{
name: cacheProfileName,
type: 'duckdb',
allow: '*',
connection: { ['persistent-path']: cacheLayerPersistentFileName },
},
]);
expect(dsFromCacheLayer.injectedProfiles).toEqual([
{ name: 'test-duck', type: 'duckdb', allow: '*' },
{ name: cacheProfileName, type: 'duckdb', allow: '*' },
{
name: cacheProfileName,
type: 'duckdb',
allow: '*',
connection: { ['persistent-path']: cacheLayerPersistentFileName },
},
]);
});

Expand Down

0 comments on commit 453d8a5

Please sign in to comment.