Workaround: keep the cache we used to have but clear all cache for membergroups when a member group changes
This commit is contained in:
@@ -131,17 +131,18 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public IMemberGroup GetByName(string name)
|
||||
{
|
||||
// cannot use name in the cache key, 'cos when clearing the cache for a given
|
||||
// member group that has been renamed, we clear the new name but not the old
|
||||
// name - it just cannot work - and we cannot use the dirty props 'cos it won't
|
||||
// work on distributed cache - and besides, we end up caching both by name and
|
||||
// by id
|
||||
// disabling the cache entirely for now - if we want to cache we'd need to
|
||||
// implement some sort of cross-reference name/id cache
|
||||
|
||||
var qry = new Query<IMemberGroup>().Where(group => group.Name.Equals(name));
|
||||
var result = GetByQuery(qry);
|
||||
return result.FirstOrDefault();
|
||||
return IsolatedCache.GetCacheItem<IMemberGroup>(
|
||||
string.Format("{0}.{1}", typeof(IMemberGroup).FullName, name),
|
||||
() =>
|
||||
{
|
||||
var qry = new Query<IMemberGroup>().Where(group => group.Name.Equals(name));
|
||||
var result = GetByQuery(qry);
|
||||
return result.FirstOrDefault();
|
||||
},
|
||||
//cache for 5 mins since that is the default in the RuntimeCacheProvider
|
||||
TimeSpan.FromMinutes(5),
|
||||
//sliding is true
|
||||
true);
|
||||
}
|
||||
|
||||
public IMemberGroup CreateIfNotExists(string roleName)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
@@ -83,35 +83,28 @@ namespace Umbraco.Web.Cache
|
||||
|
||||
public override void Refresh(string jsonPayload)
|
||||
{
|
||||
ClearCache(DeserializeFromJsonPayload(jsonPayload));
|
||||
ClearCache();
|
||||
base.Refresh(jsonPayload);
|
||||
}
|
||||
|
||||
public override void Refresh(int id)
|
||||
{
|
||||
ClearCache(FromMemberGroup(ApplicationContext.Current.Services.MemberGroupService.GetById(id)));
|
||||
ClearCache();
|
||||
base.Refresh(id);
|
||||
}
|
||||
|
||||
public override void Remove(int id)
|
||||
{
|
||||
ClearCache(FromMemberGroup(ApplicationContext.Current.Services.MemberGroupService.GetById(id)));
|
||||
ClearCache();
|
||||
base.Remove(id);
|
||||
}
|
||||
|
||||
private void ClearCache(params JsonPayload[] payloads)
|
||||
private void ClearCache()
|
||||
{
|
||||
if (payloads == null) return;
|
||||
|
||||
var memberGroupCache = ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.GetCache<IMemberGroup>();
|
||||
payloads.ForEach(payload =>
|
||||
{
|
||||
if (payload != null && memberGroupCache)
|
||||
{
|
||||
memberGroupCache.Result.ClearCacheItem(RepositoryBase.GetCacheIdKey<IMemberGroup>(payload.Id));
|
||||
}
|
||||
});
|
||||
|
||||
// Since we cache by group name, it could be problematic when renaming to
|
||||
// previously existing names - see http://issues.umbraco.org/issue/U4-10846.
|
||||
// To work around this, just clear all the cache items
|
||||
ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.ClearCache<IMemberGroup>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user