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;
|
2015-01-13 13:33:39 +11:00
|
|
|
|
|
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
|
|
|
|
{
|
2016-01-07 19:27:59 +01:00
|
|
|
|
ClearAllIsolatedCacheByEntityType<IUser>();
|
2016-01-06 18:08:14 +01:00
|
|
|
|
if (UserPermissionsCache)
|
|
|
|
|
|
UserPermissionsCache.Result.ClearCacheByKeySearch(CacheKeys.UserPermissionsCacheKey);
|
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
|
|
|
|
{
|
2016-01-06 18:08:14 +01:00
|
|
|
|
var userCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache<IUser>();
|
|
|
|
|
|
if (userCache)
|
|
|
|
|
|
userCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey<IUser>(id));
|
2014-03-20 12:36:13 +11:00
|
|
|
|
|
2016-01-06 18:08:14 +01:00
|
|
|
|
if (UserPermissionsCache)
|
2016-02-25 17:39:34 +01:00
|
|
|
|
UserPermissionsCache.Result.ClearCacheByKeySearch(string.Format("{0}{1}", CacheKeys.UserPermissionsCacheKey, id));
|
2016-01-06 18:08:14 +01:00
|
|
|
|
|
2014-03-20 12:36:13 +11:00
|
|
|
|
base.Remove(id);
|
2013-02-12 04:13:29 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-06 18:08:14 +01:00
|
|
|
|
private Attempt<IRuntimeCacheProvider> UserPermissionsCache
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache<EntityPermission>(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-12 04:13:29 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|