0
votes

I believe Sitecore is caching an item's workflow value and I need to be able to clear it.

The scenario is that I issue an ajax request to determine whether a specific item exists and if it does exist retrieve its Workflow field value. The user fills out a form and they have the options to Save or Submit that form; when they submit the form it enters a Workflow state. However, even if I switch browsers the LoiHasNoWorkflow keeps the previous value unless I publish again. I have a method to clear some caches but I'm not sure which might be actually caching the field.

    public static bool ClearCache()
    {
        foreach (DictionaryEntry entry in HttpContext.Current.Cache)
        {
            HttpContext.Current.Cache.Remove((string)entry.Key);
        }

        Context.Database.Engines.TemplateEngine.Reset();
        Context.ClientData.RemoveAll();
        CacheManager.ClearAllCaches();

        return true;
    }

public bool LoiHasNoWorkflow => CBUtility.ClearCache() && string.IsNullOrEmpty(loi?.Fields["__Workflow"].Value);

How can I determine why the item's __Workflow value won't clear? I can even delete the item through Sitecore UI, refresh the page, and issue the same request but get the value when the item did exist.

1
Are your ajax request and form submit accessing the master database? When you read LoiHasNoWorkflow it is accessing the web database?Ben Golden

1 Answers

0
votes

Actually the issue turned out to be not related to the cache but my own mistake. My loi object was a static variable within that class and so it wasn't getting cleared out on every page refresh. Here is the SO deeper explanation that led me to this realization. Actually learned a bit more about how static variables.

Lifetime of ASP.NET Static Variable