Skip to content

Cache expiry missing Content Length #408

Description

@stefannikolei

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions