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
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.WhereCondition = whereCondition.WhereCondition;
objectCollection.OrderBy = "UserName";
objectCollection.ChangeParent((BaseInfo) null, (ICMSStorage) this.Generalized);
this.mUsers = objectCollection;
How can I invalidate the cache of that property to force loading data from database?
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.
Thanks Trevor, but unfortunately it doesn't help me. I had to change my code to use my custom property instead of that.
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.
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.
Please, sign in to be able to submit a new answer.