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-03-12 03:11:35 +04:00
|
|
|
|
using Umbraco.Core.Models;
|
2013-02-07 05:53:59 +06:00
|
|
|
|
using umbraco.interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
public class MediaCacheRefresher : ICacheRefresher<IMedia>
|
2013-02-07 05:53:59 +06:00
|
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
ClearCache(ApplicationContext.Current.Services.MediaService.GetById(id));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(int id)
|
|
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
ClearCache(ApplicationContext.Current.Services.MediaService.GetById(id));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Refresh(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-12 03:11:35 +04:00
|
|
|
|
public void Refresh(IMedia instance)
|
2013-02-07 05:53:59 +06:00
|
|
|
|
{
|
2013-03-12 03:11:35 +04:00
|
|
|
|
ClearCache(instance);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(IMedia instance)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearCache(instance);
|
|
|
|
|
|
}
|
2013-02-07 05:53:59 +06:00
|
|
|
|
|
2013-03-12 03:11:35 +04:00
|
|
|
|
private static void ClearCache(IMedia media)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (media == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var idPart in media.Path.Split(','))
|
2013-02-07 05:53:59 +06:00
|
|
|
|
{
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
|
2013-03-12 22:58:21 +04:00
|
|
|
|
string.Format("UL_{0}_{1}_True", CacheKeys.MediaCacheKey, idPart));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
|
|
|
|
|
|
// Also clear calls that only query this specific item!
|
2013-03-12 03:11:35 +04:00
|
|
|
|
if (idPart == media.Id.ToString())
|
2013-02-07 05:53:59 +06:00
|
|
|
|
ApplicationContext.Current.ApplicationCache.ClearCacheByKeySearch(
|
2013-03-12 22:58:21 +04:00
|
|
|
|
string.Format("UL_{0}_{1}", CacheKeys.MediaCacheKey, media.Id));
|
2013-02-07 05:53:59 +06:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|