Cache expiry missing Content Length

Open
#408 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp
Domain
backend

Research direction

Start by tracing the middleware's cache-expiry check and the SourceMetadataLru handling described in the issue. Compare cachedImage.ImageCacheMetadata.ContentLength with sourceImageMetadata.ContentLength, then add or update coverage for replacing an image and loading it again within the 30-second cache lifetime.

Written by the indexing model from the issue text.

Description

needs triage
Prerequisites
  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Web
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported
ImageSharp.Web version

4.0.1

Other Six Labors packages and versions

4.1.1

Environment (Operating system, version and so on)

win11

.NET version

net10

Description

The Middleware is checking the CacheLastWriteTime and SourceLastWriteTime.
I think it should also check if the Content Length differs.

        // Or has the source image changed since the image was last cached?
        if (cachedImage.ImageCacheMetadata.ContentLength == 0 // Fix for old cache without length property
            || cachedImage.ImageCacheMetadata.CacheLastWriteTimeUtc <= (DateTimeOffset.UtcNow - this.options.CacheMaxAge)
            || cachedImage.ImageCacheMetadata.SourceLastWriteTimeUtc != sourceImageMetadata.LastWriteTimeUtc)

vs

 if (cachedImage.ImageCacheMetadata.ContentLength == 0 // Fix for old cache without length property
            || cachedImage.ImageCacheMetadata.ContentLength != sourceImageMetadata.ContentLength
            || cachedImage.ImageCacheMetadata.CacheLastWriteTimeUtc <= (DateTimeOffset.UtcNow - this.options.CacheMaxAge)
            || cachedImage.ImageCacheMetadata.SourceLastWriteTimeUtc != sourceImageMetadata.LastWriteTimeUtc)

Btw. I hit an edge case eith the SourceMetadataLru cache. When you load the image, replace it and instantly load it (all in 30 seconds) --> This will result in old sourceImageMetadata because of the Lifetime of 30 seconds for the SourceMetadataLru

Steps to Reproduce

--

Images

No response

Dominant language
C#
Stars
446
Forks
104
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SixLabors/ImageSharp.Web

All issues in SixLabors/ImageSharp.Web

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.