Copied to clipboard

Flag this post as spam?

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


  • Shaishav Karnani from digitallymedia.com 347 posts 1624 karma points
    16 days ago
    Shaishav Karnani from digitallymedia.com
    0

    Hi,

    We are integrating Azure CDN with Umbraco. CDN is integrated and we have written helper method to make a CDN external call. However, we need to include cache-busting technique too.

    This was possible in Umbraco v7 using below package. https://our.umbraco.com/packages/developer-tools/azure-cdn-toolkit-for-umbraco/

    How can we do it using v8? Looking forward for your views.

    Cheers,

    Shaishav

  • David Armitage 347 posts 1373 karma points
    1 week ago
    David Armitage
    0

    Hi Shaishav,

    Could you possible try something simple like for example.

    Store a cache busting number within your web config. Call it something like ImageCacheVersion.

    Then when you are referencing the image urls just add a query string on the end of the url.

    .media/whatever.png?version=@(ImageCacheVersion)

    That way when you change the value in the web config then the URL is going to be different and so shouldn't be returned from the Cache.

    A simple idea but it will be checking that a query string is allowed by Azure CDN. My guess is it will be fine.

    Regards

    David

  • Amir Khan 1081 posts 2246 karma points
    1 week ago
    Amir Khan
    0

    Where in the web.config would you put this and what would the xml look like? This could be interesting to easily version up js / css as well, just not sure exactly how to implement it.

  • David Armitage 347 posts 1373 karma points
    1 week ago
    David Armitage
    0

    Here is an example of the web.config. This should get added into the appSettings section. As you can see I have added a cache busting property at the bottom.

    <add key="Umbraco.Core.DefaultUILanguage" value="en-US" />
    <add key="Umbraco.Core.UseHttps" value="false" />
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="webpages:Enabled" value="false" />
    <add key="enableSimpleMembership" value="false" />
    <add key="autoFormsAuthentication" value="false" />
    <add key="dataAnnotations:dataTypeAttribute:disableRegEx" value="false" />
    <!--<add key="owin:appStartup" value="UmbracoDefaultOwinStartup" />-->
    <add key="owin:appStartup" value="UmbracoStandardOwinStartup" />
    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="Nothing" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    <add key="CacheBuster" value="1000" /><!-- version number -->
    

    And here is code to be able to read from the web.config. ConfigurationManager.AppSettings["CacheBuster"]

    More info can be found here. https://stackoverflow.com/questions/1189364/reading-settings-from-app-config-or-web-config-in-net

    If you pop the a query string on the end of the image I think that should work.

    So the image might look something like.

    /images/image.png?version=1000

    And the version 1000 will be read from your new web.config setting. When you want to get a fresh image without using the cache then increase the version number in your web.config to 1001, 1002, 1003 and so on.

    Regards

    David

  • Amir Khan 1081 posts 2246 karma points
    1 week ago
    Amir Khan
    0

    Thank you!!

Please Sign in or register to post replies

Write your reply to:

Draft