(
ctx: HttpRouteContext,
sessionId: string,
namespace: string,
params: Record<string, unknown>,
compute: () => T,
options?: { dailyInvalidate?: boolean; extraVersion?: string }
)
| 49 | * that resource changes independently of the DB or app version. |
| 50 | */ |
| 51 | export function withAnalyticsCache<T>( |
| 52 | ctx: HttpRouteContext, |
| 53 | sessionId: string, |
| 54 | namespace: string, |
| 55 | params: Record<string, unknown>, |
| 56 | compute: () => T, |
| 57 | options?: { dailyInvalidate?: boolean; extraVersion?: string } |
| 58 | ): T { |
| 59 | const queryCacheDir = path.join(ctx.pathProvider.getCacheDir(), 'query') |
| 60 | const dateStr = options?.dailyInvalidate ? `|date:${new Date().toISOString().split('T')[0]}` : '' |
| 61 | const extraStr = options?.extraVersion ? `|${options.extraVersion}` : '' |
| 62 | const version = `${ctx.getVersion()}|${getDbFileVersion(ctx.sessionAdapter.getDbPath(sessionId))}${dateStr}${extraStr}` |
| 63 | const key = buildAnalyticsCacheKey(namespace, params) |
| 64 | return getOrComputeAnalysisCache(sessionId, key, queryCacheDir, version, compute) |
| 65 | } |
no test coverage detected