MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / withAnalyticsCache

Function withAnalyticsCache

packages/http-routes/src/analytics-cache.ts:51–65  ·  view source on GitHub ↗
(
  ctx: HttpRouteContext,
  sessionId: string,
  namespace: string,
  params: Record<string, unknown>,
  compute: () => T,
  options?: { dailyInvalidate?: boolean; extraVersion?: string }
)

Source from the content-addressed store, hash-verified

49 * that resource changes independently of the DB or app version.
50 */
51export 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}

Callers 3

registerNlpRoutesFunction · 0.90
cachedFunction · 0.90

Calls 6

getDbFileVersionFunction · 0.90
buildAnalyticsCacheKeyFunction · 0.85
getCacheDirMethod · 0.65
getVersionMethod · 0.65
getDbPathMethod · 0.65

Tested by

no test coverage detected