Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Last reviewed commit: f4dc10a |
|
Size Change: +2.31 kB (+0.03%) Total Size: 6.65 MB
ℹ️ View Unchanged
|
|
|
||
| private getCacheKey(name: string, version?: number): string { | ||
| return version === undefined ? `${name}::latest` : `${name}::version:${version}` | ||
| } |
There was a problem hiding this comment.
I would document that we enforce cache naming in the backend that prevents using :::
| private getCacheKey(name: string, version?: number): string { | |
| return version === undefined ? `${name}::latest` : `${name}::version:${version}` | |
| } | |
| // :: is restricted from use in cache names in the backend, so no chance of accidental collision | |
| private getCacheKey(name: string, version?: number): string { | |
| return version === undefined ? `${name}::latest` : `${name}::version:${version}` | |
| } |
Still a bit brittle since we could change that in the backend without realising this code exists, the ideal solution would be to use a Map<string, Map<number | undefined, CachedPrompt>> as the cache, mimicking the Python approach of a tuple as a key.
| const latestKey = this.getCacheKey(name) | ||
| const versionPrefix = `${name}::version:` | ||
| for (const key of this.cache.keys()) { | ||
| if (key === latestKey) { | ||
| this.cache.delete(key) | ||
| continue | ||
| } |
There was a problem hiding this comment.
The approach described in my previous comment would also make clearing all versions for a prompt a one liner without string manipulation.
| * @param name - Optional prompt name to clear. If not provided, clears all cached prompts. | ||
| * @param name - Optional prompt name to clear. If provided, clears all cached versions for that prompt. | ||
| */ | ||
| clearCache(name?: string): void { |
There was a problem hiding this comment.
Shouldn't this be clearCache(name?: string, version?: number): void for parity with Python's API?
Summary
versionoption toPrompts.get()so callers can request a specific published prompt version