2013-04-30 18:11:00 -07:00
|
|
|
|
using System;
|
2013-05-30 16:32:50 -07:00
|
|
|
|
using System.Collections.Generic;
|
2013-04-30 18:11:00 -07:00
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Cache
|
|
|
|
|
{
|
2013-05-22 22:12:01 -07:00
|
|
|
|
public interface ICacheManger
|
2013-04-30 18:11:00 -07:00
|
|
|
|
{
|
2013-05-29 21:55:23 -07:00
|
|
|
|
ICached<T> GetCache<T>(Type host, string name);
|
|
|
|
|
ICached<T> GetCache<T>(Type host);
|
2013-05-30 16:32:50 -07:00
|
|
|
|
//ICollection<ICached<T>> Caches<T> { get;}
|
|
|
|
|
void Clear();
|
|
|
|
|
ICollection<ICached> Caches { get; }
|
2013-05-22 22:12:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CacheManger : ICacheManger
|
|
|
|
|
{
|
2013-05-30 16:32:50 -07:00
|
|
|
|
private readonly ICached<ICached> _cache;
|
2013-04-30 18:11:00 -07:00
|
|
|
|
|
2013-05-22 22:12:01 -07:00
|
|
|
|
public CacheManger()
|
2013-04-30 18:11:00 -07:00
|
|
|
|
{
|
2013-05-30 16:32:50 -07:00
|
|
|
|
_cache = new Cached<ICached>();
|
2013-05-22 22:12:01 -07:00
|
|
|
|
|
2013-04-30 18:11:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-29 21:55:23 -07:00
|
|
|
|
public ICached<T> GetCache<T>(Type host)
|
2013-04-30 18:11:00 -07:00
|
|
|
|
{
|
2013-05-29 21:55:23 -07:00
|
|
|
|
Ensure.That(() => host).IsNotNull();
|
|
|
|
|
return GetCache<T>(host, host.FullName);
|
2013-05-22 22:12:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 16:32:50 -07:00
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
_cache.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICollection<ICached> Caches { get { return _cache.Values; } }
|
|
|
|
|
|
2013-05-29 21:55:23 -07:00
|
|
|
|
public ICached<T> GetCache<T>(Type host, string name)
|
2013-05-22 22:12:01 -07:00
|
|
|
|
{
|
2013-05-29 21:55:23 -07:00
|
|
|
|
Ensure.That(() => host).IsNotNull();
|
|
|
|
|
Ensure.That(() => name).IsNotNullOrWhiteSpace();
|
|
|
|
|
|
|
|
|
|
return (ICached<T>)_cache.Get(host.FullName + "_" + name, () => new Cached<T>());
|
2013-04-30 18:11:00 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|