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


C# CacheKey.EnsureFolderAndGetFileName方法代码示例

本文整理汇总了C#中CacheCow.Common.CacheKey.EnsureFolderAndGetFileName方法的典型用法代码示例。如果您正苦于以下问题:C# CacheKey.EnsureFolderAndGetFileName方法的具体用法?C# CacheKey.EnsureFolderAndGetFileName怎么用?C# CacheKey.EnsureFolderAndGetFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CacheCow.Common.CacheKey的用法示例。


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

示例1: AddOrUpdate

        public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
        {
            string fileName = key.EnsureFolderAndGetFileName(_dataRoot);

            if (File.Exists(fileName))
            {
                TraceWriter.WriteLine("Must remove file", TraceLevel.Verbose);
                TryRemove(key);
            }

            var ms = new MemoryStream();
            _serializer.SerializeAsync(TaskHelpers.FromResult(response), ms).Wait();
            ms.Position = 0;
            using (var fs = GetFile(fileName, FileMode.Create))
            {
                TraceWriter.WriteLine("Before serialise", TraceLevel.Verbose);
                ms.CopyTo(fs);
                TraceWriter.WriteLine("After serialise", TraceLevel.Verbose);
            }

            var info = new FileInfo(fileName);

            // Update database
            _database.Cache
                .Insert(new CacheItem()
                {
                    Domain = key.Domain,
                    Hash = Convert.ToBase64String(key.Hash),
                    LastAccessed = DateTime.Now,
                    LastUpdated = response.Content != null && response.Content.Headers.LastModified.HasValue ?
                        response.Content.Headers.LastModified.Value.UtcDateTime : DateTime.Now
                    ,
                    Size = info.Length
                });
            TraceWriter.WriteLine("After db update", TraceLevel.Verbose);

            // tell quota manager
            _quotaManager.ItemAdded(new CacheItemMetadata()
            {
                Domain = key.Domain,
                Key = key.Hash,
                LastAccessed = DateTime.Now,
                Size = info.Length
            });
        }
开发者ID:AlexZeitler,项目名称:CacheCow,代码行数:45,代码来源:FileStore.cs

示例2: TryGetValue

		public bool TryGetValue(CacheKey key, out HttpResponseMessage response)
		{
			response = null;


			string fileName = key.EnsureFolderAndGetFileName(_dataRoot);
			if (File.Exists(fileName))
			{
				var ms = new MemoryStream();
				using (var fs = GetFile(fileName, FileMode.Open))
				{
					TraceWriter.WriteLine("TryGetValue - before DeserializeToResponseAsync", TraceLevel.Verbose);
					fs.CopyTo(ms);
					ms.Position = 0;
				}
				response = _serializer.DeserializeToResponseAsync(ms).Result;
				TraceWriter.WriteLine("TryGetValue - After DeserializeToResponseAsync", TraceLevel.Verbose);
				if (response.Content != null)
				{
					var task = response.Content.LoadIntoBufferAsync();
					task.Wait();
					TraceWriter.WriteLine("TryGetValue - After  wait", TraceLevel.Verbose);
				}

				_database.Cache
					.UpdateByHash(new
					{
						Hash = Convert.ToBase64String(key.Hash),
						LastAccessed = DateTime.Now
					});

				TraceWriter.WriteLine("After updating Last Accessed", TraceLevel.Verbose);

			}


			return response != null;
		}
开发者ID:yyf919,项目名称:CacheCow,代码行数:38,代码来源:FileStore.cs


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