Files
Umbraco-CMS/src/Umbraco.Web/Cache/MediaCacheRefresher.cs

57 lines
1.5 KiB
C#
Raw Normal View History

using System;
using Umbraco.Core;
2013-03-12 03:00:42 +04:00
using Umbraco.Core.Cache;
using umbraco.interfaces;
namespace Umbraco.Web.Cache
{
public class MediaCacheRefresher : ICacheRefresher
{
public Guid UniqueIdentifier
{
get { return new Guid(DistributedCache.MediaCacheRefresherId); }
}
public string Name
{
get { return "Clears Media Cache from umbraco.library"; }
}
public void RefreshAll()
{
}
public void Refresh(int id)
{
ClearCache(id);
}
public void Remove(int id)
{
ClearCache(id);
}
public void Refresh(Guid id)
{
}
private static void ClearCache(int id)
{
var m = ApplicationContext.Current.Services.MediaService.GetById(id);
if (m == null) return;
foreach (var idPart in m.Path.Split(','))
{
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
2013-03-12 03:00:42 +04:00
string.Format("UL_{0}_{1}_True", CacheKeys.GetMediaCacheKey, idPart));
// Also clear calls that only query this specific item!
if (idPart == m.Id.ToString())
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
2013-03-12 03:00:42 +04:00
string.Format("UL_{0}_{1}", CacheKeys.GetMediaCacheKey, id));
}
}
}
}