/// <summary>
        ///     Initialize asset cache module, with custom parameters.
        /// </summary>
        /// <param name="maximalSize">
        ///     Cache's maximal size in bytes.
        /// </param>
        /// <param name="maximalCount">
        ///     Cache's maximal count of assets.
        /// </param>
        /// <param name="expirationTime">
        ///     Asset's expiration time.
        /// </param>
        protected void Initialize(long maximalSize, int maximalCount, TimeSpan expirationTime)
        {
            if (maximalSize <= 0 || maximalCount <= 0)
            {
                //MainConsole.Instance.Debug("[ASSET CACHE]: Cenome asset cache is not enabled.");
                return;
            }

            if (expirationTime <= TimeSpan.Zero)
            {
                // Disable expiration time
                expirationTime = TimeSpan.MaxValue;
            }

            // Create cache and add synchronization wrapper over it
            m_cache =
                CnmSynchronizedCache <string, AssetBase> .Synchronized(new CnmMemoryCache <string, AssetBase>(
                                                                           maximalSize, maximalCount, expirationTime));

            MainConsole.Instance.DebugFormat(
                "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})",
                maximalSize,
                maximalCount,
                expirationTime);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns a <see cref="ICnmCache{TKey,TValue}"/> wrapper that is synchronized (thread safe).
 /// </summary>
 /// <param name="cache">
 /// The <see cref="ICnmCache{TKey,TValue}"/> to synchronize.
 /// </param>
 /// <returns>
 /// A <see cref="ICnmCache{TKey,TValue}"/> wrapper that is synchronized (thread safe).
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="cache"/>is null.
 /// </exception>
 public static ICnmCache <TKey, TValue> Synchronized(ICnmCache <TKey, TValue> cache)
 {
     if (cache == null)
     {
         throw new ArgumentNullException("cache");
     }
     return(cache.IsSynchronized ? cache : new CnmSynchronizedCache <TKey, TValue>(cache));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Close region module.
 /// </summary>
 public void Close()
 {
     if (m_enabled)
     {
         m_enabled = false;
         m_cache.Clear();
         m_cache = null;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize region module.
        /// </summary>
        /// <param name="source">
        /// Configuration source.
        /// </param>
        public void Initialise(IConfigSource source)
        {
            m_cache   = null;
            m_enabled = false;

            IConfig moduleConfig = source.Configs["Modules"];

            if (moduleConfig == null)
            {
                return;
            }

            string name = moduleConfig.GetString("AssetCaching");

            Log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);

            if (name != Name)
            {
                return;
            }

            // This module is used
            long     maxSize        = DefaultMaxSize;
            int      maxCount       = DefaultMaxCount;
            TimeSpan expirationTime = DefaultExpirationTime;

            IConfig assetConfig = source.Configs["AssetCache"];

            if (assetConfig != null)
            {
                // Get optional configurations
                maxSize        = assetConfig.GetLong("MaxSize", DefaultMaxSize);
                maxCount       = assetConfig.GetInt("MaxCount", DefaultMaxCount);
                expirationTime =
                    TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int)DefaultExpirationTime.TotalMinutes));

                // Debugging purposes only
                m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
            }

            Initialize(maxSize, maxCount, expirationTime);
        }
        public void Initialize(IConfigSource config, IRegistryCore registry)
        {
            m_cache = null;

            IConfig moduleConfig = config.Configs["Modules"];

            if (moduleConfig == null)
            {
                return;
            }

            string name = moduleConfig.GetString("AssetCaching");

            //MainConsole.Instance.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);

            if (name != Name)
            {
                return;
            }

            long     maxSize        = DefaultMaxSize;
            int      maxCount       = DefaultMaxCount;
            TimeSpan expirationTime = DefaultExpirationTime;

            IConfig assetConfig = config.Configs["AssetCache"];

            if (assetConfig != null)
            {
                // Get optional configurations
                maxSize        = assetConfig.GetLong("MaxSize", DefaultMaxSize);
                maxCount       = assetConfig.GetInt("MaxCount", DefaultMaxCount);
                expirationTime =
                    TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int)DefaultExpirationTime.TotalMinutes));

                // Debugging purposes only
                m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
            }

            Initialize(maxSize, maxCount, expirationTime);
            registry.RegisterModuleInterface <IImprovedAssetCache>(this);
        }
        /// <summary>
        ///     Initialize asset cache module, with custom parameters.
        /// </summary>
        /// <param name="maximalSize">
        ///     Cache's maximal size in bytes.
        /// </param>
        /// <param name="maximalCount">
        ///     Cache's maximal count of assets.
        /// </param>
        /// <param name="expirationTime">
        ///     Asset's expiration time.
        /// </param>
        protected void Initialize(long maximalSize, int maximalCount, TimeSpan expirationTime)
        {
            if (maximalSize <= 0 || maximalCount <= 0)
            {
                //MainConsole.Instance.Debug("[ASSET CACHE]: Cenome asset cache is not enabled.");
                return;
            }

            if (expirationTime <= TimeSpan.Zero)
            {
                // Disable expiration time
                expirationTime = TimeSpan.MaxValue;
            }

            // Create cache and add synchronization wrapper over it
            m_cache = CnmSynchronizedCache<string, AssetBase>.Synchronized(new CnmMemoryCache<string, AssetBase>( maximalSize, maximalCount, expirationTime));
            MainConsole.Instance.DebugFormat(
                "[ASSET CACHE]: Cenome asset cache enabled (MaxSize = {0} bytes, MaxCount = {1}, ExpirationTime = {2})",
                maximalSize,
                maximalCount,
                expirationTime);
        }
        public void Initialize(IConfigSource config, IRegistryCore registry)
        {
            m_cache = null;

            IConfig moduleConfig = config.Configs["Modules"];
            if (moduleConfig == null)
                return;

            string name = moduleConfig.GetString("AssetCaching");
            //MainConsole.Instance.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);

            if (name != Name)
                return;

            long maxSize = DefaultMaxSize;
            int maxCount = DefaultMaxCount;
            TimeSpan expirationTime = DefaultExpirationTime;

            IConfig assetConfig = config.Configs["AssetCache"];
            if (assetConfig != null)
            {
                // Get optional configurations
                maxSize = assetConfig.GetLong("MaxSize", DefaultMaxSize);
                maxCount = assetConfig.GetInt("MaxCount", DefaultMaxCount);
                expirationTime =
                    TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int) DefaultExpirationTime.TotalMinutes));

                // Debugging purposes only
                m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
            }

            Initialize(maxSize, maxCount, expirationTime);
            registry.RegisterModuleInterface<IImprovedAssetCache>(this);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CnmSynchronizedCache{TKey,TValue}"/> class.
 /// Initializes a new instance of the <see cref="CnmSynchronizedCache{TKey,TValue}"/> class.
 /// </summary>
 /// <param name="cache">
 /// The cache.
 /// </param>
 private CnmSynchronizedCache(ICnmCache <TKey, TValue> cache)
 {
     m_cache    = cache;
     m_syncRoot = m_cache.SyncRoot;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initialize region module.
        /// </summary>
        /// <param name="source">
        /// Configuration source.
        /// </param>
        public void Initialise(IConfigSource source)
        {
            m_cache = null;
            m_enabled = false;

            IConfig moduleConfig = source.Configs[ "Modules" ];
            if (moduleConfig == null)
                return;

            string name = moduleConfig.GetString("AssetCaching");
            //m_log.DebugFormat("[XXX] name = {0} (this module's name: {1}", name, Name);

            if (name != Name)
                return;
            
            long maxSize = DefaultMaxSize;
            int maxCount = DefaultMaxCount;
            TimeSpan expirationTime = DefaultExpirationTime;

            IConfig assetConfig = source.Configs["AssetCache"];
            if (assetConfig != null)
            {
                // Get optional configurations
                maxSize = assetConfig.GetLong("MaxSize", DefaultMaxSize);
                maxCount = assetConfig.GetInt("MaxCount", DefaultMaxCount);
                expirationTime =
                    TimeSpan.FromMinutes(assetConfig.GetInt("ExpirationTime", (int)DefaultExpirationTime.TotalMinutes));

                // Debugging purposes only
                m_debugEpoch = assetConfig.GetInt("DebugEpoch", 0);
            }

            Initialize(maxSize, maxCount, expirationTime);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Close region module.
 /// </summary>
 public void Close()
 {
     if (m_enabled)
     {
         m_enabled = false;
         m_cache.Clear();
         m_cache = null;
     }
 }