64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Kreta.Framework.Caching
|
|
{
|
|
public class CacheManager
|
|
{
|
|
private Dictionary<Type, Cache> m_Caches = new Dictionary<Type, Cache>();
|
|
private System.Threading.ReaderWriterLockSlim m_CacheManagerLock = new System.Threading.ReaderWriterLockSlim();
|
|
|
|
public CacheManager()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adott cache kérése a managertől
|
|
/// </summary>
|
|
/// <typeparam name="CacheType">Cache típusa</typeparam>
|
|
/// <returns>Cache példány</returns>
|
|
public CacheType AquireCache<CacheType>() where CacheType : Cache
|
|
{
|
|
m_CacheManagerLock.EnterWriteLock();
|
|
try
|
|
{
|
|
if (!m_Caches.ContainsKey(typeof(CacheType)))
|
|
{
|
|
m_Caches.Add(typeof(CacheType), (Cache)Activator.CreateInstance(typeof(CacheType), new object[] { this }));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
m_CacheManagerLock.ExitWriteLock();
|
|
}
|
|
return (CacheType)m_Caches[typeof(CacheType)];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adott cache kérése a managertől, mobilból
|
|
/// </summary>
|
|
/// <typeparam name="CacheType">Cache típusa</typeparam>
|
|
/// <returns>Cache példány</returns>
|
|
public CacheType AquireCacheMobile<CacheType>() where CacheType : Cache
|
|
{
|
|
m_CacheManagerLock.EnterWriteLock();
|
|
try
|
|
{
|
|
if (!m_Caches.ContainsKey(typeof(CacheType)))
|
|
{
|
|
m_Caches.Add(typeof(CacheType), (Cache)Activator.CreateInstance(typeof(CacheType), new object[] { this }));
|
|
}
|
|
return (CacheType)m_Caches[typeof(CacheType)];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
|
}
|
|
finally
|
|
{
|
|
m_CacheManagerLock.ExitWriteLock();
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|