Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dennis Pullens 2 posts 72 karma points
    5 days ago
    Dennis Pullens
    0

    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;

    • 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.

    Thanks a lot in advance!

  • Dave Woestenborghs 3112 posts 10095 karma points MVP 3x admin c-trib
    5 days ago
    Dave Woestenborghs
    2

    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

Please Sign in or register to post replies

Write your reply to:

Draft