using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
using umbraco.cms.businesslogic.member;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
{
///
/// A cache refresher to ensure member cache is updated when members change
///
///
/// This is not intended to be used directly in your code and it should be sealed but due to legacy code we cannot seal it.
///
public class MemberCacheRefresher : CacheRefresherBase
{
protected override MemberCacheRefresher Instance
{
get { return this; }
}
public override Guid UniqueIdentifier
{
get { return new Guid(DistributedCache.MemberCacheRefresherId); }
}
public override string Name
{
get { return "Clears Member Cache"; }
}
public override void Refresh(int id)
{
ClearCache(id);
base.Refresh(id);
}
public override void Remove(int id)
{
ClearCache(id);
base.Remove(id);
}
private void ClearCache(int id)
{
ApplicationContext.Current.ApplicationCache.ClearPartialViewCache();
ApplicationContext.Current.ApplicationCache.
ClearCacheByKeySearch(string.Format("{0}_{1}", CacheKeys.MemberLibraryCacheKey, id));
ApplicationContext.Current.ApplicationCache.
ClearCacheByKeySearch(string.Format("{0}{1}", CacheKeys.MemberBusinessLogicCacheKey, id));
RuntimeCacheProvider.Current.Delete(typeof(IMember), id);
}
}
}