Refactoring singleton implementation for DatabaseFactory and Repository Cache Providers as per recommendations from http://csharpindepth.com/articles/general/singleton.aspx

Adding unit test for DatabaseFactory.
This commit is contained in:
Morten@Thinkpad-X220.ab-nat1.dk
2012-10-09 16:07:19 -02:00
parent 26b67afd33
commit f69b3e9b97
7 changed files with 42 additions and 61 deletions

View File

@@ -13,26 +13,18 @@ namespace Umbraco.Core.Persistence.Caching
internal sealed class RuntimeCacheProvider : IRepositoryCacheProvider
{
#region Singleton
private static volatile RuntimeCacheProvider _instance;
private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
private RuntimeCacheProvider() { }
private static readonly Lazy<RuntimeCacheProvider> lazy = new Lazy<RuntimeCacheProvider>(() => new RuntimeCacheProvider());
public static RuntimeCacheProvider Current
public static RuntimeCacheProvider Current { get { return lazy.Value; } }
private RuntimeCacheProvider()
{
get
{
using (new WriteLock(Lock))
{
if (_instance == null) _instance = new RuntimeCacheProvider();
}
return _instance;
}
}
#endregion
private ObjectCache _memoryCache = new MemoryCache("in-memory");
private readonly ObjectCache _memoryCache = new MemoryCache("in-memory");
private ConcurrentDictionary<string, string> _keyTracker = new ConcurrentDictionary<string, string>();
public IEntity GetById(Type type, Guid id)