This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,64 @@
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;
}
}
}