本文整理汇总了C#中ICache.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ICache.Insert方法的具体用法?C# ICache.Insert怎么用?C# ICache.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICache
的用法示例。
在下文中一共展示了ICache.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SetUp
public void SetUp()
{
mocks = new MockRepository();
mockContext = (IApplicationContext) mocks.CreateMock(typeof (IApplicationContext));
advice = new InvalidateCacheAdvice();
advice.ApplicationContext = mockContext;
cache = new NonExpiringCache();
cache.Insert(1, "one");
cache.Insert(2, "two");
cache.Insert(3, "three");
}
示例3: LoadTransformFile
public static IList<string> LoadTransformFile(ICache cache, string filePath)
{
if (cache == null)
{
throw new ArgumentNullException("cache");
}
if (filePath == null)
{
throw new ArgumentNullException("filePath");
}
string cacheKey = string.Format("transformTable-{0}", Path.GetFileName(filePath));
// read the transformation hashtable from the cache
//
var tranforms = cache[cacheKey] as IList<string>;
if (tranforms == null)
{
tranforms = new List<string>();
if (filePath.Length > 0)
{
using (StreamReader sr = File.OpenText(filePath))
{
// Read through each set of lines in the text file
//
string line = sr.ReadLine();
while (line != null)
{
line = Regex.Escape(line);
string replaceLine = sr.ReadLine();
// make sure replaceLine != null
//
if (replaceLine == null)
{
break;
}
line = line.Replace("<CONTENTS>", "((.|\n)*?)");
line = line.Replace("<WORDBOUNDARY>", "\\b");
line = line.Replace("<", "<");
line = line.Replace(">", ">");
line = line.Replace("\"", """);
replaceLine = replaceLine.Replace("<CONTENTS>", "$1");
tranforms.Add(line);
tranforms.Add(replaceLine);
line = sr.ReadLine();
}
}
// slap the ArrayList into the cache and set its dependency to the transform file.
cache.Insert(cacheKey, tranforms, new CacheDependency(filePath));
}
}
return tranforms;
}