Caching Error Kentico 12 MVC

Michael John Veloso asked on December 9, 2019 17:12

Hi,

I have a kentico 12 MVC project and hosted in web farm.

After purging the cache I encountered this "Unable to cast object of type 'CMS.Helpers.DummyItem' to type 'KenticoCloud.Delivery.DeliveryItemResponse'." when reloading the page.

Anyone encountered this error?

Thank you in advance.

Recent Answers


Trevor Fayas answered on December 9, 2019 19:54

We may need a little more context on this one, is there anyway to share some of the code where this error occurred? Are you using Kentico Cloud as the source for your content instead of Kentico 12?

0 votesVote for this answer Mark as a Correct answer

Michael John Veloso answered on December 10, 2019 02:33 (last edited on December 10, 2019 02:34)

Hi,

I am using kentico cloud.

    var response = CloudCacheHelper.Cache(cs => LoadItemAsync(codename, cs, parameters), CachingManager.GetDataCacheSettings(codename));

    public static CacheSettings GetDataCacheSettings(string cacheKey = "")
            {
                var cacheSettings = new CacheSettings(CachingHelper.DataCacheDuration, string.Format("data|{0}|{1}", CachingHelper.SiteName.ToLowerInvariant(), cacheKey.ToLowerInvariant()))
                {
                    GetCacheDependency = () =>
                    {
                        string dependencyCacheKey = String.Format("data|{0}|all", cacheKey.ToLowerInvariant());
                        return CacheHelper.GetCacheDependency(dependencyCacheKey);
                    },
                    AllowProgressiveCaching = true
                };

                return cacheSettings;
            }
            //purging
CacheHelper.TouchKey(cacheKey.Key.ToString());     
0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on December 10, 2019 02:56

Okay so this isn't a Kentico 12 issue. The code you provided is your caching with cache setting but I don't see any actual item retrieval, there loaditemasync method, can you provide that?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on December 10, 2019 20:56

Oddly i just encountered your error in a different context. It happened after calling the CacheHelper.Cache after touching the key as you are doing with the purging.

It seems the CacheHelper.TouchKey("KeyName") definitely causes something to blow up with it, i had to restart the site to stop getting that error.

May want to inquire with support on this one, seems to be some sort of bug.

0 votesVote for this answer Mark as a Correct answer

Michael John Veloso answered on December 13, 2019 04:10 (last edited on December 13, 2019 04:20)

@Trevor,

I found the issue on this after more digging.

Somehow when you touch the key using the CacheHelper.TouchKey("KeyName") if there are multiple dependencies, the Priority Status of the CacheItem changes to NotRemovable. the Data has "{DummyItem}" value.

It throws an Invalid Cast Exception because of this. I was able to resolve this by using the CacheHelper.ClearCache("KeyName", [caseSensitive = false], [logTask = true]) This will clear the cache item that starts with the KeyName you specified and logTask = true to create a webfarm task to be able to sync to the webfarm.

Not sure if this is the right way to do it, but in the meantime it works for me as I am trying to find a better way to do it.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.