Skip to content

Commit 2d3e747

Browse files
committed
Added collection cache integration test
1 parent d5fa67e commit 2d3e747

14 files changed

Lines changed: 568 additions & 161 deletions

src/packages/pongo/src/core/cache/cacheWrapper.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import type { CacheEventHooks, PongoCacheProvider } from './types';
1+
import { resolveCacheConfig } from './configResolution';
2+
import { inMemoryCacheProvider } from './inMemoryProvider';
3+
import type { CacheConfig, CacheEventHooks, PongoCacheProvider } from './types';
24

35
export const pongoCacheWrapper = (options: {
46
provider: PongoCacheProvider;
@@ -88,3 +90,25 @@ export const pongoCacheWrapper = (options: {
8890
},
8991
};
9092
};
93+
94+
export const resolveCollectionCacheProvider = (
95+
cacheOption: CacheConfig | 'disabled' | PongoCacheProvider | undefined,
96+
dbName: string,
97+
collectionName: string,
98+
): PongoCacheProvider | null => {
99+
if (cacheOption === 'disabled') return null;
100+
101+
if (cacheOption !== undefined && typeof (cacheOption as PongoCacheProvider).get === 'function')
102+
return cacheOption as PongoCacheProvider;
103+
104+
const config = resolveCacheConfig(
105+
cacheOption === undefined ? undefined : (cacheOption as CacheConfig),
106+
);
107+
if (config === 'disabled') return null;
108+
109+
const raw = inMemoryCacheProvider({
110+
...(config.max !== undefined ? { max: config.max } : {}),
111+
...(config.ttl !== undefined ? { ttl: config.ttl } : {}),
112+
});
113+
return pongoCacheWrapper({ provider: raw, dbName, collectionName });
114+
};

src/packages/pongo/src/core/cache/cacheWrapper.unit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it, vi } from 'vitest';
2-
import type { PongoCacheProvider } from './types';
32
import { pongoCacheWrapper } from './cacheWrapper';
3+
import type { PongoCacheProvider } from './types';
44

55
import type { PongoDocument } from '../typing';
66

0 commit comments

Comments
 (0)