imazen / imageflow-dotnet-server

A super-fast image server to speed up your site - deploy as a microservice, serverless, or embeddable.
https://docs.imageflow.io
GNU Affero General Public License v3.0
252 stars 33 forks source link

Returning StatusCode 304 when caching is enabled #21

Closed gerneio closed 4 years ago

gerneio commented 4 years ago

There is potentially one problem with the logic in ImageflowMiddleware.Invoke() method during identifying if we have a NotModified image. It does NOT check to see if the actual file exists on the file system (i.e. if it was cleaned up by disk caching).

For most scenarios, this will probably not be that big of a deal since the browser is just going to use its cached version of the image. However, I have a process in place that is making a request to the ImageFlow server with the "IfNoneMatch" header specified with the cacheKey that I am storing in a database. The purpose of this request is to identify the most recent cacheKey for a certain URL and then convert that cacheKey to an actual physical path. However, in the above scenario, the converted path will not point to a valid document since it was deleted by the cleanup process. So in my code, I need to check to see when this is the case and make a second request to the ImageFlow server, but this time without the "IfNoneMatch" header.

lilith commented 4 years ago

I don't see this as a problem. The image will be re-generated if it is missing, so there's no real inconsistency from the HTTP side of things.

Guessing the disk cache path is always going to be tricky, as cache cleanup could happen between the HTTP and disk requests anyway.