2013-02-12 04:13:29 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core;
|
2013-03-12 03:00:42 +04:00
|
|
|
|
using Umbraco.Core.Cache;
|
2014-01-28 10:46:59 +11:00
|
|
|
|
using Umbraco.Core.Models.Membership;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Caching;
|
2015-01-13 13:25:36 +11:00
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
2013-02-12 04:13:29 +06:00
|
|
|
|
using umbraco.interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Handles User cache invalidation/refreshing
|
|
|
|
|
|
/// </summary>
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public sealed class UserCacheRefresher : CacheRefresherBase<UserCacheRefresher>
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
2013-03-21 22:53:58 +06:00
|
|
|
|
protected override UserCacheRefresher Instance
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return this; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Guid UniqueIdentifier
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
|
|
|
|
|
get { return Guid.Parse(DistributedCache.UserCacheRefresherId); }
|
|
|
|
|
|
}
|
2013-03-21 22:53:58 +06:00
|
|
|
|
|
|
|
|
|
|
public override string Name
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
|
|
|
|
|
get { return "User cache refresher"; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override void RefreshAll()
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Clear(typeof(IUser));
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheObjectTypes<IUser>();
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.UserPermissionsCacheKey);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.UserContextCacheKey);
|
2014-03-20 12:36:13 +11:00
|
|
|
|
base.RefreshAll();
|
2013-02-12 04:13:29 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override void Refresh(int id)
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
|
|
|
|
|
Remove(id);
|
2014-03-20 12:36:13 +11:00
|
|
|
|
base.Refresh(id);
|
2013-02-12 04:13:29 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-21 22:53:58 +06:00
|
|
|
|
public override void Remove(int id)
|
2013-02-12 04:13:29 +06:00
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof (IUser), id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IUser>(id));
|
2014-01-28 10:46:59 +11:00
|
|
|
|
|
2015-01-13 13:25:36 +11:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(string.Format("{0}{1}", CacheKeys.UserPermissionsCacheKey, id));
|
2013-04-04 02:11:31 +06:00
|
|
|
|
|
|
|
|
|
|
//we need to clear all UserContextCacheKey since we cannot invalidate based on ID since the cache is done so based
|
|
|
|
|
|
//on the current contextId stored in the database
|
2015-01-13 13:25:36 +11:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheByKeySearch(CacheKeys.UserContextCacheKey);
|
2014-03-20 12:36:13 +11:00
|
|
|
|
|
|
|
|
|
|
base.Remove(id);
|
2013-02-12 04:13:29 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|