本文整理汇总了C#中System.Web.Caching.Cache类的典型用法代码示例。如果您正苦于以下问题:C# Cache类的具体用法?C# Cache怎么用?C# Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于System.Web.Caching命名空间,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryFindViewFromViewModel
protected string TryFindViewFromViewModel(Cache cache, object viewModel)
{
if (viewModel != null)
{
var viewModelType = viewModel.GetType();
var cacheKey = "ViewModelViewName_" + viewModelType.FullName;
var cachedValue = (string)cache.Get(cacheKey);
if (cachedValue != null)
{
return cachedValue != NoVirtualPathCacheValue ? cachedValue : null;
}
while (viewModelType != typeof(object))
{
var viewModelName = viewModelType.Name;
var namespacePart = viewModelType.Namespace.Substring("FODT.".Length);
var virtualPath = "~/" + namespacePart.Replace(".", "/") + "/" + viewModelName.Replace("ViewModel", "") + ".cshtml";
if (Exists(virtualPath) || VirtualPathProvider.FileExists(virtualPath))
{
cache.Insert(cacheKey, virtualPath, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
return virtualPath;
}
viewModelType = viewModelType.BaseType;
}
// no view found
cache.Insert(cacheKey, NoVirtualPathCacheValue, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
}
return null;
}
示例2: ReadJsonFromFileAndCache
public async static Task<List<Dictionary<string, object>>> ReadJsonFromFileAndCache(string pathToFile, Cache cache)
{
string jsonString = null;
Dictionary<string, List<Dictionary<string, object>>> jsonData = null;
try
{
jsonString = await Task.Run(() => ReadJsonDataFromFile(pathToFile));
jsonData = await Task.Run(() => JsonHelper.Parse(jsonString));
}
catch
{
jsonString = String.Empty;
}
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
foreach(var list in jsonData.Values)
{
result.AddRange(list);
}
CacheJson(cache, "jsonData", result, pathToFile);
return result;
}
示例3: GetDummyData
//An example of caching.
public static IEnumerable<string> GetDummyData(Cache cache)
{
var action = new Func<IEnumerable<string>>(() => { return new List<string>() { "foo", "bar", "lipsum" }; });
var things = ((IEnumerable<string>)BaseCache.GetInsertCacheItem(cache, BaseCacheNames.DummyData.ToString(), action, null));
return things;
}
示例4: Initialize
/// <summary>
/// Initializes this cache provider.
/// </summary>
public void Initialize(CacheProviderInitializationArgs args)
{
// This may seem odd, but using the ASP.NET cache outside of an ASP app
// is perfectly ok, according to this MSDN article:
// http://msdn.microsoft.com/en-us/library/ms978500.aspx
_cache = HttpRuntime.Cache;
}
示例5: CacheEntry
internal CacheEntry (Cache objManager, string strKey, object objItem,CacheDependency objDependency,
CacheItemRemovedCallback eventRemove, DateTime dtExpires, TimeSpan tsSpan,
long longMinHits, bool boolPublic, CacheItemPriority enumPriority )
{
if (boolPublic)
_enumFlags |= Flags.Public;
_strKey = strKey;
_objItem = objItem;
_objCache = objManager;
_onRemoved += eventRemove;
_enumPriority = enumPriority;
_ticksExpires = dtExpires.ToUniversalTime ().Ticks;
_ticksSlidingExpiration = tsSpan.Ticks;
// If we have a sliding expiration it overrides the absolute expiration (MS behavior)
// This is because sliding expiration causes the absolute expiration to be
// moved after each period, and the absolute expiration is the value used
// for all expiration calculations.
if (tsSpan.Ticks != Cache.NoSlidingExpiration.Ticks)
_ticksExpires = DateTime.UtcNow.AddTicks (_ticksSlidingExpiration).Ticks;
_objDependency = objDependency;
if (_objDependency != null)
// Add the entry to the cache dependency handler (we support multiple entries per handler)
_objDependency.Changed += new CacheDependencyChangedHandler (OnChanged);
_longMinHits = longMinHits;
}
示例6: LessCssHttpHandler
public LessCssHttpHandler(
Cache cache,
IVirtualFileSystemWrapper virtualFileSystemWrapper,
AssetHandlerSettings assetHandlerConfig)
: base(cache, virtualFileSystemWrapper, assetHandlerConfig)
{
}
示例7: Dump
public List<Node> Dump(Cache session)
{
return session.Cast<DictionaryEntry>()
.OrderBy(x => x.Key)
.Select(x => Process("item", (string)x.Key, x.Value, 0))
.ToList();
}
示例8: GetService
public static AggregationCategorizationService GetService(Cache cache, String userId)
{
try
{
if (cache["AggCatService_" + userId] == null)
{
string certificateFile = System.Configuration.ConfigurationManager.AppSettings["PrivateKeyPath"];
string password = System.Configuration.ConfigurationManager.AppSettings["PrivateKeyPassword"];
X509Certificate2 certificate = new X509Certificate2(certificateFile, password);
string consumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
string consumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
string issuerId = System.Configuration.ConfigurationManager.AppSettings["SAMLIdentityProviderID"];
SamlRequestValidator samlValidator = new SamlRequestValidator(certificate, consumerKey, consumerSecret, issuerId, userId);
ServiceContext ctx = new ServiceContext(samlValidator);
cache.Add("AggCatService_" + userId, new AggregationCategorizationService(ctx), null, DateTime.Now.AddMinutes(50),
Cache.NoSlidingExpiration, CacheItemPriority.High, null);
}
return (AggregationCategorizationService)cache["AggCatService_" + userId];
}
catch (Exception ex)
{
throw new Exception("Unable to create AggCatService: " + ex.Message);
}
}
示例9: BritBoxingTwitterInfo
public BritBoxingTwitterInfo(Cache cache, TwitterService service)
{
_cache = cache;
_service = service;
UpdateContent();
}
示例10: DotNetCacheManager
/// <summary>
/// 构造函数
/// </summary>
public DotNetCacheManager()
{
if (HttpContext.Current != null)
{
cache = HttpContext.Current.Cache;
}
}
示例11: SiteCache
static SiteCache()
{
DayFactor = 17280;
HourFactor = 720;
MinuteFactor = 12;
Factor = 5;
_cache = HttpRuntime.Cache;
}
示例12: Scheduler
/// <summary>
/// Initializes a new instance of the <see cref="Scheduler"/> class.
/// </summary>
/// <param name="tasks">The tasks.</param>
/// <param name="internalCheckInterval">The internal check interval (in seconds).</param>
public Scheduler(SchedulerTask[] tasks, int internalCheckInterval = 120)
{
_tasks = tasks;
_internalCheckInterval = internalCheckInterval;
_cache = HttpRuntime.Cache;
_logger = LogManager.GetLogger("SchedulerTask");
_logger.Trace("Scheduler created.");
}
示例13: HttpListenerContextAdapter
public HttpListenerContextAdapter(HttpListenerContext context, string virtualPath, string physicalPath)
{
this.request = new HttpListenerRequestAdapter(context.Request, virtualPath, MakeRelativeUriFunc(context.Request.Url, virtualPath));
this.response = new HttpListenerResponseAdapter(context.Response);
this.server = new ConcoctHttpServerUtility(physicalPath);
this.cache = new Cache();
this.session = new HttpListenerSessionState();
}
示例14: SysCache
public SysCache(string region, IDictionary<string, string> properties)
{
this.region = region;
this.cache = HttpRuntime.Cache;
this.Configure(properties);
this.rootCacheKey = this.GenerateRootCacheKey();
this.StoreRootCacheKey();
}
示例15: FieldCacheFacade
public FieldCacheFacade()
{
string xmlFile = HttpContext.Current.Server.MapPath("~/schemamapping.xml");
CacheDependency xmlDependency = new CacheDependency(xmlFile);
Cache cache = new Cache();
cache.Insert("", null, xmlDependency);
}