Hi,
Can anyone tell me a little more about profile caching? The reason I ask is that I introduced profile caching in all my modules in the last 2 monthsand I want to see if I can remove it or if I need to be aware of anything,.
Basically whenever I retrieved a user with UserController.GetUser(UserID) I noticed it made 4 hits to the DB. Sometimes I get back 50 profiles at a time and the DB traffic was going mad, so I implemented caching.
It now does a check and if the user is already in the cache it gets it from there or gets it from the DB and adds it to the cache - eg.:
public UserInfo GetUserFromCacheOrDB(int portalID, int userID, int profileCacheSeconds)
{
//check if caching must be used - check if this user record is in the cache, and use it
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)
{
DataCache.SetCache(cacheKey, user, DateTime.Now.AddSeconds(profileCacheSeconds));
}
}
return user;
}
It is configurable in all my modules and I chose abosulte caching over sliding as mysite has heavy traffic and it would never update. Can someone tell me a little more about how the core profile caching works (I noticed the method name in an error somewhere). TIA