Cache invalidation

Anton Grekhovodov asked on September 25, 2017 11:02

I have a method which contains the code below:

var currentContact = OnlineMarketingContext.GetCurrentContact();
if (currentContact == null && !currentContact.Users.Any()) return;
ContactMembershipInfoProvider.SetRelationship(MemberTypeEnum.CmsUser, user, currentContact, true);
CacheHelper.TouchKey("cms.user|all"); // because Users property depends on this dummy key

After that I execute currentContact.Users which still returns previous cached results. Desciption of Users property of ContactInfo type in Kentico 8:

public virtual InfoObjectCollection Users
{
  get
  {
    if (this.mUsers == null)
    {
      WhereCondition whereCondition = new WhereCondition().WhereIn("UserID", (IList<int>) ContactMembershipInfoProvider.GetRelationships(this.ContactID, MemberTypeEnum.CmsUser));
      InfoObjectCollection objectCollection = new InfoObjectCollection("cms.user");
      objectCollection.AddCacheDependencies("cms.user|all", "cms.userrole|all");
      objectCollection.WhereCondition = whereCondition.WhereCondition;
      objectCollection.OrderBy = "UserName";
      objectCollection.ChangeParent((BaseInfo) null, (ICMSStorage) this.Generalized);
      this.mUsers = objectCollection;
    }
    return this.mUsers;
  }
}

How can I invalidate the cache of that property to force loading data from database?

Recent Answers


Trevor Fayas answered on September 25, 2017 16:24

The description is in the UserSettings, is it possible you need to touch the cms.usersettings as well? if that doesn't work, try touching by "cms.user|byid|" and the ID.

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on September 26, 2017 06:51

Thanks Trevor, but unfortunately it doesn't help me. I had to change my code to use my custom property instead of that.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on September 27, 2017 14:45 (last edited on September 27, 2017 14:51)

Anton,

Why are you reseting cache on cms_user (object/table) if you operate with om_contact? See how contacts data are cached in Kentico (debug\cache items) and touch contact key not the user key. if know for what record you want reset the cache search |byid|123 you will probably get onlinemarketingcontact|byid|123 or similar, i.e. this the key to touch.

1 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on September 27, 2017 16:38

Hi Peter,

I'm resetting cache on cms_user, because the property depends on it, see the code above. I tried to touch contact keys, it doesn't help too.

0 votesVote for this answer Mark as a Correct answer

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