public override void RemoveUserFromCache(IUser user) { if (user != null) { var usernameCacheKey = new UsernameCacheKey(Config.ConfigKey, user.UserName, user.Domain); var userIdCacheKey = new UserIdCacheKey(Config.ConfigKey, user.Id); HttpRuntime.Cache.Remove(usernameCacheKey.CacheKey); HttpRuntime.Cache.Remove(userIdCacheKey.CacheKey); } }
public override IUser GetUserByUserName(string userName, string domain) { if (userName == null || MinutesInCache == 0) { return(null); } var usernameCacheKey = new UsernameCacheKey(Config.ConfigKey, userName, domain); return(HttpRuntime.Cache[usernameCacheKey.CacheKey] as IUser); }
public override void AddUserToCache(IUser user) { if (user != null && MinutesInCache > 0) { user.MakeReadOnly(); var usernameCacheKey = new UsernameCacheKey(Config.ConfigKey, user.UserName, user.Domain); var userIdCacheKey = new UserIdCacheKey(Config.ConfigKey, user.Id); if (SlidingExpiration) { var expirationTime = new TimeSpan(0, 0, MinutesInCache, 0); HttpRuntime.Cache.Add(usernameCacheKey.CacheKey, user, null, Cache.NoAbsoluteExpiration, expirationTime, CachePriority, null); HttpRuntime.Cache.Add(userIdCacheKey.CacheKey, user, null, Cache.NoAbsoluteExpiration, expirationTime, CachePriority, null); } else { var expirationTime = DateTime.Now.AddMinutes(MinutesInCache); HttpRuntime.Cache.Add(usernameCacheKey.CacheKey, user, null, expirationTime, Cache.NoSlidingExpiration, CachePriority, null); HttpRuntime.Cache.Add(userIdCacheKey.CacheKey, user, null, expirationTime, Cache.NoSlidingExpiration, CachePriority, null); } } }