2013-02-07 05:53:59 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core;
|
2013-03-12 03:00:42 +04:00
|
|
|
|
using Umbraco.Core.Cache;
|
2013-02-07 05:53:59 +06:00
|
|
|
|
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));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
|
|
|
|
|
|
// 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));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|