using System; using System.Collections.Generic; namespace Kreta.Framework.Caching { public class CacheManager { private Dictionary m_Caches = new Dictionary(); private System.Threading.ReaderWriterLockSlim m_CacheManagerLock = new System.Threading.ReaderWriterLockSlim(); public CacheManager() { } /// /// Adott cache kérése a managertől /// /// Cache típusa /// Cache példány public CacheType AquireCache() 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)]; } /// /// Adott cache kérése a managertől, mobilból /// /// Cache típusa /// Cache példány public CacheType AquireCacheMobile() 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; } } }