当前位置: 首页>>代码示例>>C#>>正文


C# CacheEntry类代码示例

本文整理汇总了C#中CacheEntry的典型用法代码示例。如果您正苦于以下问题:C# CacheEntry类的具体用法?C# CacheEntry怎么用?C# CacheEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CacheEntry类属于命名空间,在下文中一共展示了CacheEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Intercept

        public void Intercept(IInvocation invocation)
        {
            var cacheKey = string.Format("{0}||{1}", invocation.Method.Name, invocation.Method.DeclaringType.Name);

            if (_cache.ContainsKey(cacheKey))
            {
                var entry = _cache[cacheKey];
                if (DateTime.Now < entry.Expiry)
                {
                    invocation.ReturnValue = entry.ReturnValue;
                    return;
                }
            }

            invocation.Proceed();
         
            // Can we cache this entry?
            if (invocation.MethodInvocationTarget.GetCustomAttributes(typeof (CacheAttribute), true).Length == 0) 
                return;
            
            var newEntry = new CacheEntry()
                               {
                                   Expiry = DateTime.Now.AddSeconds(5), 
                                   ReturnValue = invocation.ReturnValue
                               };
            _cache[cacheKey] = newEntry;
        }
开发者ID:PaulStovell,项目名称:presentations,代码行数:27,代码来源:CacheInterceptor.cs

示例2: GetData

        /// <summary>
        /// Returns a Matrix with the data for the TimeStep, Item
        /// TimeStep counts from 0, Item from 1.
        /// Lower left in Matrix is (0,0)
        /// </summary>
        /// <param name="TimeStep"></param>
        /// <param name="Item"></param>
        /// <param name="Layer"></param>
        /// <returns></returns>
        public Matrix GetData(int TimeStep, int Item)
        {
            CacheEntry cen;

              Dictionary<int, CacheEntry> _timeValues;

              if (!_bufferData.TryGetValue(Item, out _timeValues))
              {
            _timeValues = new Dictionary<int, CacheEntry>();
            _bufferData.Add(Item, _timeValues);
              }
              if (!_timeValues.TryGetValue(TimeStep, out cen))
              {
            ReadItemTimeStep(TimeStep, Item);
            Matrix _data = new Matrix(_numberOfRows, _numberOfColumns);
            int m = 0;
            for (int i = 0; i < _numberOfRows; i++)
              for (int j = 0; j < _numberOfColumns; j++)
              {
            _data[i, j] = dfsdata[m];
            m++;
              }
            cen = new CacheEntry(AbsoluteFileName, Item, TimeStep, _data);
            _timeValues.Add(TimeStep, cen);
            CheckBuffer();
              }
              else
            AccessList.Remove(cen);
              AccessList.AddLast(cen);
              return cen.Data;
        }
开发者ID:shobaravi,项目名称:mikeshewrapper,代码行数:40,代码来源:DFS2.cs

示例3: Id_ShouldReturnCorrectValue

		public void Id_ShouldReturnCorrectValue(
			[Frozen]Guid id,
			CacheEntry<object> sut)
		{
			//assert
			sut.Id.Should().Be(id);
		}
开发者ID:Galad,项目名称:Hanno,代码行数:7,代码来源:CacheEntryTests.cs

示例4: GetPrimePlatSellOrders

        public static async Task<long?> GetPrimePlatSellOrders(string primeName)
        {
            CacheEntry<long?> cacheItem;
            if (_marketCache.TryGetValue(primeName, out cacheItem))
            {
                if (!cacheItem.IsExpired(_expirationTimespan))
                {
                    return cacheItem.Value;
                }
            }

            var textInfo = new CultureInfo("en-US", false).TextInfo;

            var partName = textInfo.ToTitleCase(primeName.ToLower());

            if (_removeBPSuffixPhrases.Any(suffix => partName.EndsWith(suffix + " Blueprint")))
            {
                partName = partName.Replace(" Blueprint", "");
            }

            // Since Warframe.Market is still using the term Helmet instead of the new one, TODO: this might change
            partName = partName.Replace("Neuroptics", "Helmet");

            if (_fixedQueryStrings.ContainsKey(partName))
            {
                //Some of Warframe.Market's query strings are mangled (extra spaces, misspellings, words missing) fix them manually...
                partName = _fixedQueryStrings[partName];
            }

            string jsonData;
            using (var client = new WebClient())
            {
                var uri = new Uri(_baseUrl + Uri.EscapeDataString(partName));

                try
                {
                    jsonData = await client.DownloadStringTaskAsync(uri);

                    dynamic result = JsonConvert.DeserializeObject(jsonData);

                    // when the server responds anything that is not 200 (HTTP OK) don't bother doing something else
                    if (result.code != 200)
                    {
                        Debug.WriteLine($"Error with {partName}, Status Code: {result.code.Value}");
                        _marketCache[primeName] = new CacheEntry<long?>(null);
                        return null;
                    }

                    IEnumerable<dynamic> sellOrders = result.response.sell;
                    long? smallestPrice = sellOrders.Where(order => order.online_status).Min(order => order.price);

                    _marketCache[primeName] = new CacheEntry<long?>(smallestPrice);
                    return smallestPrice;
                }
                catch
                {
                    return null;
                }
            }            
        }
开发者ID:Xeio,项目名称:VoidRewardParser,代码行数:60,代码来源:PlatinumPrices.cs

示例5: Insert

		public bool Insert(Segment seg)
		{
			Debug.Assert(Exists(seg.SegmentID) == false);

			int pos = (int)(seg.SegmentID % m_size);

			CacheEntry head = m_data[pos];

			if (head == null)
				m_data[pos] = new CacheEntry(seg);
			else
			{
				while (head.Next != null &&head.Segment.SegmentID != seg.SegmentID)
				{
					head = head.Next;
				}
				if (head.Segment.SegmentID == seg.SegmentID)
					return false;
				else
				{
					head.Next = new CacheEntry(seg,null);
				}
			}

			m_count ++;
			return true;
		}
开发者ID:luanzhu,项目名称:OOD.NET,代码行数:27,代码来源:CacheHashtable.cs

示例6: Lookup

        public CacheEntry Lookup(string fullname)
        {
            string[] names = fullname.Split('\\');

            CacheEntry current = this;
            CacheEntry child = null;
            foreach (string entry in names)
            {
                if (current.Children == null)
                    current.Children = new Dictionary<string, CacheEntry>();

                if (current.Children.TryGetValue(entry, out child))
                {
                    current = child;
                }
                else
                {
                    CacheEntry cache = new CacheEntry(entry);
                    current.Children[entry] = cache;
                    cache.Parent = current;
                    current = cache;
                }
            }

            return current;
        }
开发者ID:mushuanli,项目名称:nekodrive,代码行数:26,代码来源:NFSCache.cs

示例7: CreateCacheEntry

        private CacheEntry CreateCacheEntry(Type type)
        {
            var encoderType = typeof(IFrameEncoder<>).MakeGenericType(type);

            // Func<object, Stream, object, Task> callback = (encoder, body, value) =>
            // { 
            //   return ((IStreamEncoder<T>)encoder).Encode(body, (T)value);
            // }

            var encoderParam = Expression.Parameter(typeof(object), "encoder");
            var bodyParam = Expression.Parameter(typeof(Stream), "body");
            var valueParam = Expression.Parameter(typeof(object), "value");

            var encoderCast = Expression.Convert(encoderParam, encoderType);
            var valueCast = Expression.Convert(valueParam, type);
            var encode = encoderType.GetMethod("Encode", BindingFlags.Public | BindingFlags.Instance);
            var encodeCall = Expression.Call(encoderCast, encode, bodyParam, valueCast);
            var lambda = Expression.Lambda<Func<object, Stream, object, Task>>(encodeCall, encoderParam, bodyParam, valueParam);

            var entry = new CacheEntry
            {
                Encode = lambda.Compile(),
                Encoder = _serviceProvider.GetRequiredService(encoderType)
            };

            return entry;
        }
开发者ID:davidfowl,项目名称:ServerStack,代码行数:27,代码来源:FrameOutput.cs

示例8: IndexAddTask

 public IndexAddTask(QueryIndexManager indexManager, object key, CacheEntry value, OperationContext operationContext)
 {
     _key = key;
     _entry = value;
     _indexManager = indexManager;
     _operationContext = operationContext;
 }
开发者ID:javithalion,项目名称:NCache,代码行数:7,代码来源:QueryIndexManager.cs

示例9: Cache

            public static void Cache(DiagnosticAnalyzer analyzer, object key, CacheEntry entry)
            {
                AssertKey(key);

                // add new cache entry
                var analyzerMap = s_map.GetOrAdd(analyzer, _ => new ConcurrentDictionary<object, CacheEntry>(concurrencyLevel: 2, capacity: 10));
                analyzerMap[key] = entry;
            }
开发者ID:TyOverby,项目名称:roslyn,代码行数:8,代码来源:DiagnosticIncrementalAnalyzer.InMemoryStorage.cs

示例10: Sanity

        public void Sanity()
        {
            var ceStr = new CacheEntry<string>(1, "3");

            Assert.AreEqual(DateTime.MinValue, ceStr.LastAccessed);
            Assert.AreEqual(1, ceStr.Key);
            Assert.AreEqual("3", ceStr.Val);
            Assert.IsTrue(ceStr.LastAccessed.AddMinutes(1) > DateTime.Now);
        }
开发者ID:dfugate,项目名称:code-interviews-vs,代码行数:9,代码来源:CacheEntryTest.cs

示例11: AddEntryAsync

 public async Task AddEntryAsync(CacheEntry entry, HttpResponseMessage response)
 {
     CacheEntryContainer cacheEntryContainer = GetOrCreateContainer(entry.Key);
     lock (syncRoot)
     {
         cacheEntryContainer.Entries.Add(entry);
         _responseCache[entry.VariantId] = response;
     }
 }
开发者ID:hapikit,项目名称:hapikit.net,代码行数:9,代码来源:InMemoryContentStore.cs

示例12: GetContentAsync

 public async Task<CacheContent> GetContentAsync(CacheEntry cacheEntry, string secondaryKey)
 {
     var inMemoryCacheEntry = _responseCache[cacheEntry.Key];
     if (inMemoryCacheEntry.Responses.ContainsKey(secondaryKey))
     {
         return await CloneAsync(inMemoryCacheEntry.Responses[secondaryKey]);
     }
     return null;
 }
开发者ID:paulcbetts,项目名称:Tavis.PrivateCache,代码行数:9,代码来源:InMemoryContentStore.cs

示例13: AsyncBroadcastCustomNotifyRemoval

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="data"></param>
 public AsyncBroadcastCustomNotifyRemoval(ClusterCacheBase parent, object key, CacheEntry entry, ItemRemoveReason reason, OperationContext operationContext, EventContext eventContext)
 {
     _parent = parent;
     _key = key;
     _entry = entry;
     _reason = reason;
     _operationContext = operationContext;
     _eventContext = eventContext;
 }
开发者ID:javithalion,项目名称:NCache,代码行数:14,代码来源:AsyncBroadcastCustomNotifyRemoval.cs

示例14: Create

 public static CacheEntry Create(object rawValue, DateTime createdAt, object options = null)
 {
     var opts = options.AsDictionary();
     var entry = new CacheEntry(null);
     entry.Value = rawValue;
     entry.CreatedAt = createdAt;
     entry.Compressed = opts["compressed"].AsBoolean();
     return entry;
 }
开发者ID:meadiagenic,项目名称:Stockpile,代码行数:9,代码来源:Entry.cs

示例15: GetInstanceOf

        public static object GetInstanceOf(Type providerType, object[] providerArgs)
        {
            CacheEntry entry = new CacheEntry(providerType, providerArgs);

            object instance = instances[entry];
            return instance == null
                ? instances[entry] = Reflect.Construct(providerType, providerArgs)
                : instance;
        }
开发者ID:ChrisMissal,项目名称:shouldly,代码行数:9,代码来源:ProviderCache.cs


注:本文中的CacheEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。