sonarr-repo-only/NzbDrone.Common/Cache/CacheManger.cs

34 lines
742 B
C#
Raw Normal View History

2013-05-01 01:11:00 +00:00
using System;
using NzbDrone.Common.EnsureThat;
namespace NzbDrone.Common.Cache
{
public interface ICacheManger
2013-05-01 01:11:00 +00:00
{
ICached<T> GetCache<T>(Type type);
ICached<T> GetCache<T>(object host);
}
public class CacheManger : ICacheManger
{
private readonly ICached<object> _cache;
2013-05-01 01:11:00 +00:00
public CacheManger()
2013-05-01 01:11:00 +00:00
{
_cache = new Cached<object>();
2013-05-01 01:11:00 +00:00
}
public ICached<T> GetCache<T>(Type type)
2013-05-01 01:11:00 +00:00
{
Ensure.That(() => type).IsNotNull();
return (ICached<T>)_cache.Get(type.FullName, () => new Cached<T>());
}
public ICached<T> GetCache<T>(object host)
{
return GetCache<T>(host.GetType());
2013-05-01 01:11:00 +00:00
}
}
}