Re-extract cached resource when its source content changes#6562
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
Re-extract cached resource when its source content changes#6562TimurRakhmatullin86 wants to merge 1 commit into
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
ResourceCacheService copied a resource into the local cache only when the target file did not yet exist, so a resource replaced in place kept its previously extracted (stale) copy. A classpath resource packaged in a fat jar resolves to a "jar" URI scheme rather than "classpath", so it is cached; rebuilding the jar with a different model.onnx then reuses the old extracted file and the wrong embedding dimensions are served until the temp cache is deleted by hand. Refresh the cached copy when the original resource's size differs from the cached file, or when the original has been modified more recently, and add a regression test covering an in-place source change. Fixes spring-projectsgh-6219 Signed-off-by: Timur Rakhmatullin <174210871+TimurRakhmatullin86@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-6219
ResourceCacheServicecopies a resource into the local cache only when the target file does not yet exist, so a resource that is replaced in place keeps its previously extracted (stale) copy forever.When a
classpath:resource is packaged inside a fat jar its URI scheme resolves tojarrather thanclasspath, so it is not excluded from caching and gets extracted to the temp cache. The cache path is derived only from the resource location, which is stable across builds. Rebuilding the jar with a differentmodel.onnxtherefore reuses the old extracted file, andTransformersEmbeddingModelkeeps serving the previous model's embedding dimensions until the temp directory is deleted by hand (e.g. a 768-dim model is used to query a 384-dim index).This refreshes the cached copy when the original resource's content length differs from the cached file, or when the original has been modified more recently than the cached copy. Both are cheap metadata reads; when either is unavailable the existing cached copy is kept, preserving current behavior for resources that cannot report size/last-modified.
A regression test reproduces an in-place source change and asserts the cache is refreshed. It fails without the fix and passes with it.