本文整理汇总了C#中ICacheProvider.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheProvider.Add方法的具体用法?C# ICacheProvider.Add怎么用?C# ICacheProvider.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICacheProvider
的用法示例。
在下文中一共展示了ICacheProvider.Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContent
public OutputContent GetContent(ICacheProvider cacheProvider, Mode mode)
{
var upgraded = false;
_lock.EnterUpgradeableReadLock();
try
{
// check the cache first
var returnValue = cacheProvider.Get<OutputContent>(GetCacheKeyFor(VirtualPath, mode));
if (returnValue == null)
{
Log.WriteLine("Generating Content For '{0}'", VirtualPath);
_lock.EnterWriteLock();
upgraded = true;
byte[] rejuicedValue = null;
var file = new FileInfo(PhysicalPath);
// clear existing dependencies
_dependencies.Clear();
var minificationProvider = MinificationRegistry.Get(ResourceType);
var notFound = false;
try
{
var fileBytes = File.ReadAllBytes(PhysicalPath);
rejuicedValue = FileTransformationPipeline.TransformInputFile(this, fileBytes);
}
catch (IOException)
{
}
// Combined value
var combinedValue = new OutputContent
{
Content = rejuicedValue,
ContentHash = rejuicedValue.HashArray(),
AllowClientCaching = false,
ContentType =
ResourceType == ResourceType.Css ? "text/css" : "text/javascript",
LastModifiedDate = file.LastWriteTimeUtc
};
var dependencies = GetDependencies();
cacheProvider.Add(GetCacheKeyFor(VirtualPath, Mode.Combine), combinedValue, dependencies);
returnValue = combinedValue;
if (Mode == Mode.Minify && !notFound)
{
Log.WriteLine("Minifying Content For '{0}'", VirtualPath);
// Minified value
byte[] minifiedContent = null;
try
{
minifiedContent = minificationProvider.Minify(rejuicedValue);
}
catch (Exception e)
{
// Yes, catching Exception is bad. However, anyone can plug in their own minification provider
// and throw any exception they want. We want to make sure that exceptions thrown by rejuicer
// have the filename inside them. So we just wrap the exception here & throw the wrapped exception.
throw new InvalidOperationException(string.Format("Encountered exception trying minify invalid JavaScript for file '{0}'.", VirtualPath), e);
}
var minifiedValue = new OutputContent
{
Content = minifiedContent,
ContentHash = minifiedContent.HashArray(),
AllowClientCaching = false,
ContentType =
ResourceType == ResourceType.Css
? "text/css"
: "text/javascript",
LastModifiedDate = file.LastWriteTimeUtc
};
cacheProvider.Add(GetCacheKeyFor(VirtualPath, mode), minifiedValue, dependencies);
returnValue = minifiedValue;
}
}
return returnValue;
}
finally
{
if (upgraded)
{
_lock.ExitWriteLock();
}
_lock.ExitUpgradeableReadLock();
}
}