We're currently in the middle of automating functionality that enriches products with images. Before, for each product, a content editor had to manually upload and select (through Media Pickers) product images. Each product has a lot of varieties in color and characteristics, so this was quite a hassle.
Luckily we are now able to retrieve these images from the suppliers' API. For each product we request at the API we get a list of URL's that we can download. We store these images on a logical location on the server's disk (E.g. /media/productname/color.jpg). This also enables us to generate the URL of the image source without consulting Umbraco and the corresponding Media Picker. So far so good.
However, this approach introduces a problem; when a product's image is updated this way, the URL stays the same and both the Image Processor and the browser still show the old image from the cache. We are trying to solve this problem, but we have the feeling our solution might be a bit devious.
What we are trying so far;
After updating the image on disk, ask the Image Processor what the path of the image is in cache (including our used crops) and deleting it there using System.IO.File.Delete.
Change the URL in the HTML in a way that the browser will retrieve the updated image and thus shows the user the correct image.
We'd really appreciate some thoughts and ideas on the matter. Is this the way to go? Are there alternatives/solutions we're missing? Etc.
What I've tried so far is to call the Remove method of the CacheIndex manually. This is the same method that is called from the IsNewOrUpdatedAsync method. Unfortunately this did not update the image on refresh, and I even saw that the image was still on disk in the cache folder.
Therefore I have a feeling that a custom version for the disk cache that overrides this method might not work. But it could be that I'm missing something by using this 'shortcut'.
The problem is that the path to the image is not updated in the RTE field when you change the file associated with a media item. So it still uses the old file.
Image cache when changing source images on disk
Hello everyone,
We're currently in the middle of automating functionality that enriches products with images. Before, for each product, a content editor had to manually upload and select (through Media Pickers) product images. Each product has a lot of varieties in color and characteristics, so this was quite a hassle.
Luckily we are now able to retrieve these images from the suppliers' API. For each product we request at the API we get a list of URL's that we can download. We store these images on a logical location on the server's disk (E.g. /media/productname/color.jpg). This also enables us to generate the URL of the image source without consulting Umbraco and the corresponding Media Picker. So far so good.
However, this approach introduces a problem; when a product's image is updated this way, the URL stays the same and both the Image Processor and the browser still show the old image from the cache. We are trying to solve this problem, but we have the feeling our solution might be a bit devious.
What we are trying so far;
We'd really appreciate some thoughts and ideas on the matter. Is this the way to go? Are there alternatives/solutions we're missing? Etc.
Thanks a lot in advance!
Hi Dennis,
Maybe you can create a custom version of the disk cache for image processor :
http://imageprocessor.org/imageprocessor-web/extending/#iimagecache
You could than create one that inherits the default diskcache and override the IsNewOrUpdatedAsync method to check if the image is updated.
And the update the caching configuration to use your new diskcache implementation : http://imageprocessor.org/imageprocessor-web/configuration/
Will ping James South on twitter to give his thoughts about this.
Dave
Hi Dave,
Thanks for your suggestion!
What I've tried so far is to call the Remove method of the CacheIndex manually. This is the same method that is called from the IsNewOrUpdatedAsync method. Unfortunately this did not update the image on refresh, and I even saw that the image was still on disk in the cache folder.
Therefore I have a feeling that a custom version for the disk cache that overrides this method might not work. But it could be that I'm missing something by using this 'shortcut'.
Hi Dennis,
I left a comment on the issue you raised : https://github.com/umbraco/Umbraco-CMS/issues/3869
The problem is that the path to the image is not updated in the RTE field when you change the file associated with a media item. So it still uses the old file.
Dave
is working on a reply...