本文整理汇总了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
});
}
示例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;
}