Repository navigation
feat(LLMsDocsCli): auto no-cache when not found component #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,8 +70,20 @@ public async Task<string> GetComponentAsync(string name, CancellationToken ct = | |
| throw new ArgumentException("Component name is required.", nameof(name)); | ||
| } | ||
|
|
||
| var entry = ParseIndex(await GetIndexAsync(ct)) | ||
| var index = ""; | ||
| var usedCachedIndex = _useCache && !_refresh && TryReadFreshCache("llms.txt", out index); | ||
| if (!usedCachedIndex) | ||
| { | ||
| index = await GetIndexAsync(ct); | ||
| } | ||
|
|
||
| var entry = ParseIndex(index) | ||
| .FirstOrDefault(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase)); | ||
| if (entry is null && usedCachedIndex) | ||
| { | ||
| entry = ParseIndex(await FetchAsync("llms.txt", ct, refresh: true)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Stale indexes stay fresh When concurrent refreshes fetch different index revisions, Serialize refreshes for each shared index and commit its body and metadata together, so concurrent responses cannot overwrite or mix revisions. Prompt for AI agentsIn `tools/BootstrapBlazor.LLMsDocs.Cli/Services/LlmsDocsClient.cs` at line 84:
**Stale indexes stay fresh**
When concurrent refreshes fetch different index revisions, `WriteContent` can overwrite a newer `llms.txt` body or pair an older body with newer metadata; a later 304 then treats that stale body as fresh for 24 hours, so `get` misses newly published components.
Serialize refreshes for each shared index and commit its body and metadata together, so concurrent responses cannot overwrite or mix revisions. |
||
| .FirstOrDefault(e => string.Equals(e.Name, name, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
| if (entry is null) | ||
| { | ||
| throw new FileNotFoundException($"Component not found in index: {name}"); | ||
|
|
@@ -112,7 +124,7 @@ public async Task<IReadOnlyList<ComponentEntry>> SearchAsync(string query, int l | |
|
|
||
| // ---- core fetch ------------------------------------------------------- | ||
|
|
||
| private async Task<string> FetchAsync(string relativePath, CancellationToken ct) | ||
| private async Task<string> FetchAsync(string relativePath, CancellationToken ct, bool refresh = false) | ||
| { | ||
| if (!_isRemote) | ||
| { | ||
|
|
@@ -127,7 +139,7 @@ private async Task<string> FetchAsync(string relativePath, CancellationToken ct) | |
|
|
||
| var url = new Uri(_baseUri!, relativePath); | ||
|
|
||
| if (_useCache && !_refresh && TryReadFreshCache(relativePath, out var fresh)) | ||
| if (_useCache && !_refresh && !refresh && TryReadFreshCache(relativePath, out var fresh)) | ||
| { | ||
| return fresh; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Concurrent cache update skips retry
When another process writes a fresh index containing no requested component between the initial cache check and
GetIndexAsync's cache check,GetIndexAsynccan read a newly written cache after the initial check misses, whileusedCachedIndexremains false; if that index lacks the requested name,GetComponentAsyncskips the automatic refresh and reports the component as not found.Use the cache result and its provenance from a single lookup, or ensure that a miss on the initial lookup forces the subsequent index fetch to bypass cache.
Prompt for AI agents