本文整理汇总了C#中ICache.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ICache.Remove方法的具体用法?C# ICache.Remove怎么用?C# ICache.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICache
的用法示例。
在下文中一共展示了ICache.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunCacheTests
private static void RunCacheTests(ICache cache)
{
cache.Insert("ByteArray", new byte[] {0, 1, 2, 3}, CachePriority.Normal);
cache.Insert("String", "Hello World", CachePriority.Normal);
cache.Insert("Object", new TestObject("Test Object", 1234), CachePriority.Normal);
var byteArray = cache.Lookup("ByteArray");
Assert.IsNotNull(byteArray);
Assert.AreEqual(4, byteArray.Length);
for (int i = 0; i < 4; i++) Assert.AreEqual(i, byteArray[i]);
var cachedString = cache.Lookup<string>("String");
Assert.IsNotNull(cachedString);
Assert.AreEqual("Hello World", cachedString);
var cachedObject = cache.Lookup<TestObject>("Object");
Assert.IsNotNull(cachedObject);
Assert.AreEqual("Test Object", cachedObject.StringValue);
Assert.AreEqual(1234, cachedObject.LongValue);
cache.Remove("Object");
Assert.IsNull(cache.Lookup("Object"));
Assert.IsFalse(cache.ContainsKey("Object"));
Assert.IsTrue(cache.ContainsKey("String"));
}
示例2: MaybePurgeCache
// scan the cacheurls table, compare uris with counts > 0 to uris in cache, if match then evict uri and decrement count
public static void MaybePurgeCache(ICache cache)
{
try
{
var purgeable_entities = FetchPurgeableCacheDicts();
GenUtils.LogMsg("info", String.Format("MaybePurgeCache: {0} purgeable entities", purgeable_entities.Count), null);
foreach (var purgeable_entity in purgeable_entities)
{
var purgeable_cache_url = (string)purgeable_entity["cached_uri"];
if (cache[purgeable_cache_url] != null)
{
GenUtils.LogMsg("info", "MaybePurgeCache", purgeable_cache_url);
cache.Remove(purgeable_cache_url);
var obj = HttpUtils.FetchUrl(new Uri(purgeable_cache_url)); // rewarm the cache
var count = (int)purgeable_entity["count"];
count -= 1;
if (count < 0)
{
count = 0;
GenUtils.LogMsg("warning", "CacheUtils.MaybePurgeCache", "count went subzero, reset to zero");
}
purgeable_entity["count"] = count;
var rowkey = TableStorage.MakeSafeRowkeyFromUrl(purgeable_cache_url);
ts.UpdateEntity(cache_control_tablename, cache_control_partkey, rowkey, purgeable_entity);
}
}
}
catch (Exception e)
{
GenUtils.PriorityLogMsg("exception", "MaybePurgeCache", e.Message + e.StackTrace);
}
}