Copied to clipboard

Flag this post as spam?

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


  • Richard Apelgren 2 posts 72 karma points
    Feb 28, 2022 @ 15:32
    Richard Apelgren
    0

    IPublishedContentCache inside RecurringHostedServiceBase?

    Hi,

    I'm trying to get access to the cached content inside an RecurringHostedServiceBase.

    It does not seem to work by doing like

    public class MyTask : RecurringHostedServiceBase

    public MyTask( ...IUmbracoContextFactory umbracoContextFactory... ) { this.umbracoContextFactory = umbracoContextFactory; } ...

    public override async Task PerformExecuteAsync(object state) { IPublishedContentCache contentCache = this.umbracoContextFactory.EnsureUmbracoContext().UmbracoContext.Content;

    // so far so good, not runtime errors or so, contentCache is not null

    var count = contentCache.GetAtRoot().Count();

    // count = 0 // it seems empty

    // in other context, for ex in a controller, same site will contain count=2, in our case

    // have also tried to get specifik cached content like contentCache.GetById(1234); this is null

    }

    What is the easiest way to get access to this cached content in this context? In Umbraco 8 version of this, there were no problems getting access to an populated instance of IPublishedContentCache ( when inherit from RecurringTaskBase )

    Thanks in advance :)

  • anh-duc-le 38 posts 152 karma points
    Jun 04, 2024 @ 20:14
    anh-duc-le
    0

    Did you ever find an answer to this issue?

Please Sign in or register to post replies

Write your reply to:

Draft