本文整理汇总了C#中ICacheManager.Put方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheManager.Put方法的具体用法?C# ICacheManager.Put怎么用?C# ICacheManager.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICacheManager
的用法示例。
在下文中一共展示了ICacheManager.Put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEachMethod
public static void TestEachMethod(ICacheManager<object> cache)
{
cache.Clear();
cache.Add("key", "value", "region");
cache.AddOrUpdate("key", "region", "value", _ => "update value", new UpdateItemConfig(2, VersionConflictHandling.EvictItemFromOtherCaches));
cache.Expire("key", "region", TimeSpan.FromDays(1));
var val = cache.Get("key", "region");
var item = cache.GetCacheItem("key", "region");
cache.Put("key", "region", "put value");
cache.RemoveExpiration("key", "region");
object update2;
cache.TryUpdate("key", "region", _ => "update 2 value", out update2);
object update3 = cache.Update("key", "region", _ => "update 3 value");
cache.Remove("key", "region");
cache.Clear();
cache.ClearRegion("region");
}
示例2: TestEachMethod
public static void TestEachMethod(ICacheManager<object> cache)
{
cache.Clear();
cache.Add("key", "value", "region");
cache.AddOrUpdate("key", "region", "value", _ => "update value", 22);
cache.Expire("key", "region", TimeSpan.FromDays(1));
var val = cache.Get("key", "region");
var item = cache.GetCacheItem("key", "region");
cache.Put("key", "put value");
cache.RemoveExpiration("key");
object update2;
cache.TryUpdate("key", "region", _ => "update 2 value", out update2);
object update3 = cache.Update("key", "region", _ => "update 3 value");
cache.Remove("key", "region");
cache.Clear();
cache.ClearRegion("region");
}
示例3: Thread_RandomAccess
public void Thread_RandomAccess(ICacheManager<object> cache)
{
if (cache == null)
{
throw new ArgumentNullException("cache");
}
foreach (var handle in cache.CacheHandles)
{
Trace.TraceInformation("Using handle {0}", handle.GetType());
}
var blob = new byte[1024];
using (cache)
{
Action test = () =>
{
var hits = 0;
var misses = 0;
var tId = Thread.CurrentThread.ManagedThreadId;
try
{
for (var r = 0; r < 5; r++)
{
for (int i = 0; i < 5; i++)
{
string key = "key" + i;
object value = blob.Clone();
string region = "region" + r;
CacheItem<object> item = null;
if (r % 2 == 0)
{
item = new CacheItem<object>(key, value, ExpirationMode.Sliding, TimeSpan.FromMilliseconds(10));
}
else
{
item = new CacheItem<object>(key, value, region, ExpirationMode.Absolute, TimeSpan.FromMilliseconds(10));
}
cache.Put(item);
if (!cache.Add(item))
{
cache.Put(item);
}
var result = cache.Get(key);
if (result == null)
{
misses++;
}
else
{
hits++;
}
if (!cache.Remove(key))
{
misses++;
}
else
{
hits++;
}
Thread.Sleep(0);
}
}
}
catch (Exception ex)
{
Trace.TraceError("{1} Error: {0}", ex.Message, tId);
throw;
}
Trace.TraceInformation("Hits: {0}, Misses: {1}", hits, misses);
};
ThreadTestHelper.Run(test, 2, 1);
}
}