langfuse-core
Advanced tools
Comparing version 3.19.0 to 3.20.0
@@ -198,2 +198,3 @@ 'use strict'; | ||
this.labels = prompt.labels; | ||
this.tags = prompt.tags; | ||
this.isFallback = isFallback; | ||
@@ -279,2 +280,3 @@ } | ||
this._defaultTtlSeconds = DEFAULT_PROMPT_CACHE_TTL_SECONDS; | ||
this._refreshingKeys = new Map(); | ||
} | ||
@@ -288,2 +290,13 @@ getIncludingExpired(key) { | ||
} | ||
addRefreshingPromise(key, promise) { | ||
this._refreshingKeys.set(key, promise); | ||
promise.then(() => { | ||
this._refreshingKeys.delete(key); | ||
}).catch(() => { | ||
this._refreshingKeys.delete(key); | ||
}); | ||
} | ||
isRefreshing(key) { | ||
return this._refreshingKeys.has(key); | ||
} | ||
} | ||
@@ -1098,17 +1111,17 @@ | ||
if (cachedPrompt.isExpired) { | ||
return await this._fetchPromptAndUpdateCache({ | ||
name, | ||
version, | ||
label: options?.label, | ||
cacheTtlSeconds: options?.cacheTtlSeconds, | ||
maxRetries: options?.maxRetries, | ||
fetchTimeout: options?.fetchTimeoutMs | ||
}).catch(() => { | ||
console.warn(`Returning expired prompt cache for '${this._getPromptCacheKey({ | ||
// If the cache is not currently being refreshed, start refreshing it and register the promise in the cache | ||
if (!this._promptCache.isRefreshing(cacheKey)) { | ||
const refreshPromptPromise = this._fetchPromptAndUpdateCache({ | ||
name, | ||
version, | ||
label: options?.label | ||
})}' due to fetch error`); | ||
return cachedPrompt.value; | ||
}); | ||
label: options?.label, | ||
cacheTtlSeconds: options?.cacheTtlSeconds, | ||
maxRetries: options?.maxRetries, | ||
fetchTimeout: options?.fetchTimeoutMs | ||
}).catch(() => { | ||
console.warn(`Failed to refresh prompt cache '${cacheKey}', stale cache will be used until next refresh succeeds.`); | ||
}); | ||
this._promptCache.addRefreshingPromise(cacheKey, refreshPromptPromise); | ||
} | ||
return cachedPrompt.value; | ||
} | ||
@@ -1115,0 +1128,0 @@ return cachedPrompt.value; |
{ | ||
"name": "langfuse-core", | ||
"version": "3.19.0", | ||
"version": "3.20.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=18" | ||
}, | ||
"gitHead": "763afcb682a6be2f0f60da7e0df2c2d6a3546f94" | ||
"gitHead": "cf95aa7599d04246939d1a503c955a342bb6d06b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
568369
6481