Developer forum

Forum » Ecommerce - Standard features » Regenerate thumbnail after image rename

Regenerate thumbnail after image rename

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a solution running on DW9 and we have some issues with a stubborn cache for thumbnails after images are renamed.

Before I get very deep into investigating for a solution, is there any way I can control this caching? Or maybe force a cache invalidation on file rename? Is there any Notification I can connect to or a setting regarding file rename?

Thank you,

Adrian


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

If you rename a file, the cache would invalidate it self as the img src would be changed causing a new thumbnail to be generated and a new url in the frontend to be defined.

You can add ?donotcache=true to getimage and then it will not cache.

Or you can remove the entire /cache.net folder - but that is removing a lot of images.

If an image is sent out from getimage, it is cached by the browser. So if the name of the image does not change the browser will cache it no matter what you do. Only ctrl+f5 will work in developer tools mode.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,
Thank you for the fast reply.
I thought that this would be the right behavior and I investigated more on the claim.
The use case is different and that's why it makes it complicated.
In the project, we are using patterns for image assignment. The product receives some images, and we have dedicated uses depending on the pattern.
The use case is that for some products, {ProductNumber}_3.jpg becomes {ProductNumber}_2.jpg and vice versa. And in this case, the cache is not invalidated even if the files have different sizes.
Any suggestions for this use case?

Thank you,
Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

What cache? Browser cache? Or serverside cache?

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Server side. 

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

 

If you swap img1.jpg ↔ img2.jpg by renaming:

Windows rename preserves the file's last-write-time (the metadata timestamp of the file content doesn't change just because the name changed — it reflects when the file contents were last written).
So if img2.jpg's content is swapped into the path img1.jpg purely via rename, the LastWriteTime of what's now at img1.jpg will be the original write time of img2.jpg — which may be older than the existing cache for img1.jpg.
Result: the cache would NOT be invalidated in this case. The disk cache check cacheFile.LastWriteTime < SourceFileInfo.LastWriteTime could fail (source is older than cache), and the browser ETag would change only if the last-write times differ.

The only reliable trigger for cache reload is a change to the file's LastWriteTime. A pure rename (without a touch or content write) may not update it, so the stale cached image could be served.

 

You must be logged in to post in the forum