Ejemplo n.º 1
0
        /// <summary>
        /// 缓存
        /// </summary>
        public void Cache(string key, Texture2D tex, CacheLevel cacheLevel = CacheLevel.Cache_0)
        {
            if (string.IsNullOrEmpty(key) || tex == null)
            {
                return;
            }

            if (_pool.ContainsKey(key))
            {
                return;
            }

            long texSize = tex.width * tex.height * 4;

            if (_cacheSize + texSize > _maxSize)  //超内存,清理
            {
                long target = _maxSize / 2;

                bool end = false;

                for (byte i = 0; i < _keys.Count; i++)
                {
                    Queue <string> curQ = _keys.GetValueAnyway(i);

                    while (curQ.Count > 0)
                    {
                        string toDeleteKey = curQ.Dequeue();

                        Texture2D tmp = _pool.GetValueAnyway(toDeleteKey);

                        _pool.Remove(toDeleteKey);

                        if (tmp != null)
                        {
                            long tmpSize = tmp.width * tmp.height * 4;

                            _cacheSize -= tmpSize;

                            if (_cacheSize <= target)
                            {
                                end = true;
                                break;
                            }
                        }
                    }

                    if (end)
                    {
                        Resources.UnloadUnusedAssets();
                        break;
                    }
                }
            }

            Queue <string> levelQ = _keys.GetValueAnyway((byte)cacheLevel);

            levelQ?.Enqueue(key);
            _pool[key]  = tex;
            _cacheSize += texSize;
        }
Ejemplo n.º 2
0
 internal CacheDescriptor(CacheLevel level, CacheAssociativity associativity, Int16 lineSize, Int32 size, ProcessorCacheType type)
 {
     m_level         = level;
     m_associativity = associativity;
     m_lineSize      = lineSize;
     m_size          = size;
     m_type          = type;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 分帧预加载图片
 /// </summary>
 private static IEnumerator PreloadPerFrame(string[] urls, CacheLevel cacheLevel)
 {
     if (urls != null && urls.Length > 0)
     {
         for (int i = 0; i < urls.Length; i++)
         {
             Load(urls[i], null, cacheLevel);
             yield return(null);
         }
     }
 }
        public void GetOrderedParametersReturnsCachedParameters(CacheLevel cacheLevel)
        {
            var configuration = new BuildConfiguration();
            var constructor   = typeof(SimpleConstructor).GetConstructors().First();

            var sut = new DefaultParameterResolver(cacheLevel);

            var first  = sut.GetOrderedParameters(configuration, constructor);
            var second = sut.GetOrderedParameters(configuration, constructor);

            first.Should().BeSameAs(second);
        }
Ejemplo n.º 5
0
        public void GetOrderedPropertiesReturnsCachedValueWhenCacheEnabled(CacheLevel cacheLevel)
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(SlimModel);

            var sut = new DefaultPropertyResolver(cacheLevel);

            var first  = sut.GetOrderedProperties(configuration, type);
            var second = sut.GetOrderedProperties(configuration, type);

            first.Should().BeSameAs(second);
        }
Ejemplo n.º 6
0
		public static List<uint> GetCacheSizes(CacheLevel level)
		{
			var mc = new ManagementClass("Win32_CacheMemory");
			var moc = mc.GetInstances();
			var cacheSizes = new List<uint>(moc.Count);

			cacheSizes.AddRange(moc
			  .Cast<ManagementObject>()
			  .Where(p => (ushort)(p.Properties["Level"].Value) == (ushort)level)
			  .Select(p => (uint)(p.Properties["MaxCacheSize"].Value)));

			return cacheSizes;
		}
Ejemplo n.º 7
0
        /// <summary>
        /// 设置缓存提供者
        /// </summary>
        /// <param name="provider">缓存提供者</param>
        /// <param name="level">缓存级别</param>
        public static void SetProvider(ICacheProvider provider, CacheLevel level)
        {
            ValidateHelper.Begin().NotNull(provider, "缓存提供者");
            switch (level)
            {
            case CacheLevel.First:
                Providers[0] = provider;
                break;

            case CacheLevel.Second:
                Providers[1] = provider;
                break;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 批量预加载
        /// 进缓存池
        /// </summary>
        /// <typeparam name="T">实体对象</typeparam>
        /// <param name="array">对象集合</param>
        /// <param name="urlGetter">获取url方法</param>
        /// <param name="cacheLevel">缓存优先级</param>
        public static void Preload <T>(T[] array, Func <T, string> urlGetter, CacheLevel cacheLevel = CacheLevel.Cache_0)
        {
            if (array == null || urlGetter == null)
            {
                return;
            }

            string[] urls = new string[array.Length];

            for (int i = 0; i < array.Length; i++)
            {
                urls[i] = urlGetter.Invoke(array[i]);
            }

            Task.CreateTask(PreloadPerFrame(urls, cacheLevel));
        }
Ejemplo n.º 9
0
 private static string CacheLevelToString(CacheLevel cacheLevel)
 {
     switch (cacheLevel)
     {
         case CacheLevel.Public:
             return "public";
         case CacheLevel.Private:
             return "private";
     }
     return "no-cache";
 }
Ejemplo n.º 10
0
		public static long GetCacheSize(CacheLevel level)
		{
			return GetCacheSizes(level).Sum(x => x);
		}
Ejemplo n.º 11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="FactoryTypeCreator" /> class.
 /// </summary>
 /// <param name="cacheLevel">The cache level to use for resolved methods.</param>
 public FactoryTypeCreator(CacheLevel cacheLevel)
 {
     CacheLevel = cacheLevel;
 }
Ejemplo n.º 12
0
 public CacheAttribute(CacheLevel cacheLevel, CacheTimeout timeout)
 {
     CacheTimeout = (int)timeout;
     CacheLevel = cacheLevel;
 }
Ejemplo n.º 13
0
 public CacheAttribute(CacheLevel cacheLevel, int minutesToTimeout)
 {
     CacheTimeout = minutesToTimeout;
     CacheLevel = cacheLevel;
 }
Ejemplo n.º 14
0
 public CacheAttribute(CacheLevel cacheLevel)
 {
     CacheTimeout = Settings.GlobalSettings.CacheTimeout;
     CacheLevel = cacheLevel;
 }