当前位置: 首页>>代码示例>>C#>>正文


C# ICache.Insert方法代码示例

本文整理汇总了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"));
        }
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:25,代码来源:CachingTests.cs

示例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");
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:13,代码来源:InvalidateCacheAdviceTests.cs

示例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("<", "&lt;");
                            line = line.Replace(">", "&gt;");
                            line = line.Replace("\"", "&quot;");

                            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;
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:64,代码来源:Transform.cs


注:本文中的ICache.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。