Copied to clipboard

Flag this post as spam?

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


  • David Armitage 508 posts 2078 karma points
    Jan 11, 2020 @ 02:29
    David Armitage
    0

    Umbraco 8 Refresh IPublishedContentCache

    Hi Guys,

    I have an interface helper which gets some site settings from node in Umbaco.

    For some reason when I update the settings it doesn't refresh the IPublishedContentCache. I think there is either some delay on it or it requires me to restart my app.

    private readonly IUmbracoContextFactory _umbracoContextFactory;
    
            public SiteHelper(IUmbracoContextFactory umbracoContextFactory)
            {
                _umbracoContextFactory = umbracoContextFactory;
            }
    
            public SiteSettings GetSiteSettings()
            {
                SiteSettings siteSettings;
    
                using (UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext())
                {
                    IPublishedContentCache contentHelper = umbracoContextReference.UmbracoContext.Content;
                    siteSettings = contentHelper.GetById(1114) as SiteSettings;
                }
    
                return siteSettings;
            }
    

    I am ensuring the contact because this might be used in some hangfire events and other places where it might need this.

    Does anyone know if there is a way to force refresh the IPublishedContentCache? I am thinking I can use an composer.

    I know how to set the composer / event up on publish but I am just wanting the line of code that will refresh the cache.

    Thanks in advanced.

    David

  • David Armitage 508 posts 2078 karma points
    Jan 11, 2020 @ 02:53
    David Armitage
    0

    Wow so even stranger.

    1. So I have my helper class. ISiteHelper siteHelper

    2. This contains my method GetSiteSettings

    3. My SurfaceController has ISiteHelper denendency injection.

    4. When I get the site settings within my SurfaceController they are correct and seem to update find when I change the node within Umbraco.

    Here is the strange part...

    1. I then have an email service IEmailService. This gets used in my SurfaceController to send a specific email. Nothing too special

    2. The email requires some site settings so my IEmailService has has ISiteHelper denendency injection.

    3. When I use the ISiteHelper within my email service to get the site settings they are different.

    It appears that when I make the changes in Umbraco they get updated in my controller but the service still sees the old cache.

    This is very strange because both examples are using the same ISiteHelper, same method which should be looking at the same data.

    There is no mistake here and I have triple checked. I have compared all this in the watch window.

    Has anyone got any ideas at all why it would act like this?


    As a fix I am going to get my SiteSettings in the SurfactController since this is working and pass then into the service method rather than relying on DI within my service.

  • Arun 141 posts 404 karma points
    Feb 01, 2022 @ 08:10
    Arun
    0

    Hi
    Any update on this?

Please Sign in or register to post replies

Write your reply to:

Draft