1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-28 10:37:41 +00:00
Lidarr/NzbDrone.Common/Cache/CacheManger.cs

36 lines
892 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 host, string name);
ICached<T> GetCache<T>(Type 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 host)
2013-05-01 01:11:00 +00:00
{
Ensure.That(() => host).IsNotNull();
return GetCache<T>(host, host.FullName);
}
public ICached<T> GetCache<T>(Type host, string name)
{
Ensure.That(() => host).IsNotNull();
Ensure.That(() => name).IsNotNullOrWhiteSpace();
return (ICached<T>)_cache.Get(host.FullName + "_" + name, () => new Cached<T>());
2013-05-01 01:11:00 +00:00
}
}
}