Hi,
I do extensive userprofile caching in all my modules (it's Rodney from Smart-Thinker.com, I can't post new posts with my usual DNN account). I was recently examining my cache with a cache viewer and I think I may be caching duplicate information.
So my quesions are:
1) Are UserProfiles cached in the core?
2) If so, when are they cached, and how? (I saw a method called "ClearUserCache" that takes in a username - I can't find where it is set).
3) If so, what is cached? The profile properties and the roles?
If they are cached then I will change my caching methods to use the same key ( I use string cacheKey = portalID.ToString() + "UserID" + userID.ToString();) so that I am not doubling the cache info.
Out of interest (if you got this far ;) - here is the code that I use:
public UserInfo GetUserFromCacheOrDB(int portalID, int userID, int profileCacheSeconds)
{
string cacheKey = portalID.ToString() + "UserID" + userID.ToString();
UserInfo user;
bool userInCache = (DataCache.GetCache(cacheKey) != null);
if (profileCacheSeconds > 0 && userInCache)
{
user = (UserInfo)DataCache.GetCache(cacheKey);
}
else
{
//get it from the DB
user = new UserController().GetUser(portalID, userID);
if (user != null && profileCacheSeconds > 0 && !userInCache)
{
//add it to the cache with an absoulte expiry time (otherwise it may never update)
DataCache.SetCache(cacheKey, user, DateTime.Now.AddSeconds(profileCacheSeconds));
}
}
return user;
}