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


C# Cache类代码示例

本文整理汇总了C#中Cache的典型用法代码示例。如果您正苦于以下问题:C# Cache类的具体用法?C# Cache怎么用?C# Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Cache类属于命名空间,在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main(string[] args)
    {
      var couchbaseConfig = new Couchbase.Configuration.CouchbaseClientConfiguration();
      couchbaseConfig.Bucket = "larm";
      couchbaseConfig.Urls.Add(new Uri("http://10.0.252.63:8091/pools"));
      var cache = new Cache(new Couchbase.CouchbaseClient(couchbaseConfig));
      var portalRepository = new PortalRepository().WithConfiguration("user id=larm-app;password=0n44Fx4f4m2jNtuLuA6ym88mr3h40D;server=mysql01.cpwvkgghf9fg.eu-west-1.rds.amazonaws.com;persist security info=True;database=larm-portal;Allow User Variables=True;CharSet=utf8;");
      var portal = new PortalApplication(cache, new ViewManager(new Dictionary<string, IView>(), cache), portalRepository, new DatabaseLoggerFactory(portalRepository));
      var mcm = new McmModule();
      mcm.Load(portal);

      const uint PageSize = 100;
      var indexedCount = 0;

      for (uint i = 0; ; i++)
      {
        var objects = mcm.McmRepository.ObjectGet(null, i, PageSize, true, true, true, true, true, null);

        portal.ViewManager.GetView("Search").Index(objects);
        portal.ViewManager.GetView("Object").Index(objects);

        Console.SetCursorPosition(0,Console.CursorTop);
        Console.Write("Objects indexed: {0}", ++indexedCount);
        if (objects.Count != PageSize) break;
      }
    }
开发者ID:CHAOS-Community,项目名称:CHAOS.Portal.MCM,代码行数:26,代码来源:Program.cs

示例2: CreateCacheContainingFirstThousandCountingNumbers

 private Cache<int, string> CreateCacheContainingFirstThousandCountingNumbers()
 {
     Cache<int, string> c = new Cache<int, string>();
     foreach (KeyValuePair<int, string> entry in Enumerable.Range(1, 1000).Select(i => new KeyValuePair<int, string>(i, i.ToString())))
         c.Add(entry);
     return c;
 }
开发者ID:michael085,项目名称:StopGuessing,代码行数:7,代码来源:CacheTest.cs

示例3: TerrainRenderer

        public TerrainRenderer(World world, WorldRenderer wr)
        {
            this.world = world;
            this.map = world.Map;

            var tileSize = new Size( Game.CellSize, Game.CellSize );
            var tileMapping = new Cache<TileReference<ushort,byte>, Sprite>(
                x => Game.modData.SheetBuilder.Add(world.TileSet.GetBytes(x), tileSize));

            var vertices = new Vertex[4 * map.Bounds.Height * map.Bounds.Width];

            terrainSheet = tileMapping[map.MapTiles.Value[map.Bounds.Left, map.Bounds.Top]].sheet;

            int nv = 0;

            var terrainPalette = wr.Palette("terrain").Index;

            for( int j = map.Bounds.Top; j < map.Bounds.Bottom; j++ )
                for( int i = map.Bounds.Left; i < map.Bounds.Right; i++ )
                {
                    var tile = tileMapping[map.MapTiles.Value[i, j]];
                    // TODO: move GetPaletteIndex out of the inner loop.
                    Util.FastCreateQuad(vertices, Game.CellSize * new float2(i, j), tile, terrainPalette, nv, tile.size);
                    nv += 4;

                    if (tileMapping[map.MapTiles.Value[i, j]].sheet != terrainSheet)
                        throw new InvalidOperationException("Terrain sprites span multiple sheets");
                }

            vertexBuffer = Game.Renderer.Device.CreateVertexBuffer( vertices.Length );
            vertexBuffer.SetData( vertices, nv );
        }
开发者ID:nevelis,项目名称:OpenRA,代码行数:32,代码来源:TerrainRenderer.cs

示例4: GetCounterCache

    public static CounterCache GetCounterCache(Cache cache, SessionManager manager)
    {
        try
        {
            if (s_CounterCache.Expired)
            {
                lock (s_CounterCache)
                {
                    if (s_CounterCache.Expired)
                    {
                        s_CounterCache.Flush(manager);
                    }
                }
            }
        }
        catch(Exception ex)
        {
            manager.BlogService.EventLogWriteEntry(string.Format("GetCounterCache failed to flush the cache. {0}",
                ex.Message), EventLogEntryType.Error);

            s_CounterCache = new CounterCache();
        }

        return s_CounterCache;
    }
开发者ID:dblock,项目名称:dblog,代码行数:25,代码来源:CounterCache.cs

示例5: CsdlSemanticsAssertTypeExpression

		public CsdlSemanticsAssertTypeExpression(CsdlAssertTypeExpression expression, IEdmEntityType bindingContext, CsdlSemanticsSchema schema) : base(schema, expression)
		{
			this.operandCache = new Cache<CsdlSemanticsAssertTypeExpression, IEdmExpression>();
			this.typeCache = new Cache<CsdlSemanticsAssertTypeExpression, IEdmTypeReference>();
			this.expression = expression;
			this.bindingContext = bindingContext;
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:CsdlSemanticsAssertTypeExpression.cs

示例6: RunTest100000

        /*[Test]
        public void RunTest100000()
        {
            MaxIterations = 100000;
            RunTest();
        }*/
        /*[Test]
        public void RunTest10000000()
        {
            MaxIterations = 10000000;
            RunTest();
        }*/
        private void RunTest()
        {
            NumIterations = 0;

            Cache = new Cache<long, CachedObject>(CreateForCache);

            Exception = null;

            CreatedObjects = new HashSet<long>();

            List<Thread> threads = new List<Thread>();

            for (int ctr = 0; ctr < Environment.ProcessorCount; ctr++)
            {
                Thread thread = new Thread(RunTestThread);
                thread.Name = "Cache test thread " + ctr.ToString();
                thread.Start();

                threads.Add(thread);
            }

            foreach (Thread thread in threads)
                thread.Join();

            if (null != Exception)
                throw Exception;
        }
开发者ID:GWBasic,项目名称:ObjectCloud,代码行数:39,代码来源:TestCache.cs

示例7: should_keep_cache_if_versions_same

        public async Task should_keep_cache_if_versions_same()
        {
            var cacheConfiguration = new CacheConfiguration(1024, 5, 1024, 5);

            var cacheContainer = InitializeCacheContainer();
            var storage = (TestStorage)cacheContainer.Resolve<IStorage>();

            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));

            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                //when at least one value set cache is written
                await cache.Set("some_entry", 42);
            }

            //cache should not be cleanued up if versions in storage and executing assembly differ
            cacheContainer.Register<IVersionProvider, TestVersionProvider>().WithValue("version", new Version(1, 1));
            using (var cache = new Cache(cacheContainer, cacheConfiguration))
            {
                await cache.Initialize();
                storage.KeyToStreams.Should().NotBeEmpty();
                cache.Get<Int32>("some_entry").Result.Value.Should().Be(42);
            }
        }
开发者ID:IvanLeonenko,项目名称:windows-cache,代码行数:25,代码来源:When_version_is_stored_in_cache.cs

示例8: SetUp

        public void SetUp()
        {
            testee = new Cache<string, string>(8);

            var field = testee.GetType().GetField("items", BindingFlags.Instance | BindingFlags.NonPublic);
            items = field.GetValue(testee) as List<CacheItem<string, string>>;
        }
开发者ID:kennedykinyanjui,项目名称:Projects,代码行数:7,代码来源:CacheTest.cs

示例9: ValueAndIsDirtyTest

        public void ValueAndIsDirtyTest()
        {
            int value = 3;
            int factoryCallCount = 0;
            var cache = new Cache<int>(() =>
            {
                factoryCallCount++;
                return value;
            });

            Assert.IsTrue(cache.IsDirty);
            Assert.AreEqual(0, factoryCallCount);

            Assert.AreEqual(3, cache.Value);
            Assert.IsFalse(cache.IsDirty);
            Assert.AreEqual(1, factoryCallCount);

            // Now the cached value is used.
            Assert.AreEqual(3, cache.Value);
            Assert.IsFalse(cache.IsDirty);
            Assert.AreEqual(1, factoryCallCount);

            value = 4;
            cache.SetDirty();
            Assert.IsTrue(cache.IsDirty);

            Assert.AreEqual(4, cache.Value);
            Assert.IsFalse(cache.IsDirty);
            Assert.AreEqual(2, factoryCallCount);

            AssertHelper.ExpectedException<ArgumentNullException>(() => new Cache<int>(null));
        }
开发者ID:jbe2277,项目名称:waf,代码行数:32,代码来源:CacheTest.cs

示例10: EventListenerRequest

 public EventListenerRequest(IEventContract contract, Cache cache)
     : base(contract.Reference, HttpMethod.Get)
 {
     this.contract = contract;
     this.cache = cache;
     cts = new CancellationTokenSource();
 }
开发者ID:snargledorf,项目名称:Sharpbase,代码行数:7,代码来源:EventListenerRequest.cs

示例11: LuaScriptContext

 public LuaScriptContext()
 {
     Log.Write("debug", "Creating Lua script context");
     Lua = new Lua();
     Lua.HookException += OnLuaException;
     functionCache = new Cache<string, LuaFunction>(Lua.GetFunction);
 }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:7,代码来源:LuaScriptContext.cs

示例12: SubscriptionCache

        public SubscriptionCache(ChannelGraph graph, IEnumerable<ITransport> transports)
        {
            if (!transports.Any())
            {
                throw new Exception(
                    "No transports are registered.  FubuTransportation cannot function without at least one ITransport");
            }

            _graph = graph;
            _transports = transports;

            _volatileNodes = new Cache<Uri, ChannelNode>(uri =>
            {
                var transport = _transports.FirstOrDefault(x => x.Protocol == uri.Scheme);
                if (transport == null)
                {
                    throw new UnknownChannelException(uri);
                }

                var node = new ChannelNode { Uri = uri, Key = uri.ToString() };
                node.Channel = transport.BuildDestinationChannel(node.Uri);

                return node;
            });
        }
开发者ID:joemcbride,项目名称:fubumvc,代码行数:25,代码来源:SubscriptionCache.cs

示例13: CsdlSemanticsPropertyValueBinding

		public CsdlSemanticsPropertyValueBinding(CsdlSemanticsTypeAnnotation context, CsdlPropertyValue property) : base(property)
		{
			this.valueCache = new Cache<CsdlSemanticsPropertyValueBinding, IEdmExpression>();
			this.boundPropertyCache = new Cache<CsdlSemanticsPropertyValueBinding, IEdmProperty>();
			this.context = context;
			this.property = property;
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:CsdlSemanticsPropertyValueBinding.cs

示例14: for_each_attribute

        public void for_each_attribute()
        {
            var cache = new Cache<string, string>
            {
                OnMissing = key =>
                {
                    Assert.Fail(key + " does not exist");
                    return null;
                }
            };

            var node = new JsonNode("Test");
            node.InnerText = "something";

            node["a"] = "1";
            node["b"] = "2";
            node["c"] = "3";

            node.ForEachAttribute((key, value) => cache[key] = value);

            cache.Count.ShouldEqual(3);
            cache["a"].ShouldEqual("1");
            cache["b"].ShouldEqual("2");
            cache["c"].ShouldEqual("3");
        }
开发者ID:adymitruk,项目名称:storyteller,代码行数:25,代码来源:JsonNodeTester.cs

示例15: TextureFactory

 public TextureFactory(Engine engine)
 {
     _missingTexture = engine.Content.Load<Texture2D>("Textures\\missing-texture");
     _landCache = new Cache<int, Texture2D>(TimeSpan.FromMinutes(5), 0x1000);
     _lastCacheClean = DateTime.MinValue;
     _textures = new Textures(engine);
 }
开发者ID:andyhebear,项目名称:HappyQ-WowServer,代码行数:7,代码来源:TextureFactory.cs


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