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


C# DocumentStore.DisableAggressiveCaching方法代码示例

本文整理汇总了C#中Raven.Client.Document.DocumentStore.DisableAggressiveCaching方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore.DisableAggressiveCaching方法的具体用法?C# DocumentStore.DisableAggressiveCaching怎么用?C# DocumentStore.DisableAggressiveCaching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Client.Document.DocumentStore的用法示例。


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

示例1: Can_Aggressively_Cache

        public void Can_Aggressively_Cache()
        {
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8081"
            }.Initialize())
            {
                var customer = new Customer
                               {
                                   Name = "Matt",
                                   Age = 32
                               };

                store.JsonRequestFactory.LogRequest +=
                    (sender, args) => Console.WriteLine("Http Request: {0} status={1}", args.Url, args.Status);

                using (var session = store.OpenSession())
                {
                    //This is never cached, because it's a "PUT" not a "GET"
                    session.Store(customer);
                    session.SaveChanges();
                    var sessionVer = session.Load<Customer>(customer.Id);
                    Console.WriteLine("Session Version:\n\t{0}: Name \"{1}\", Age={2}\n",
                                      sessionVer.Id, sessionVer.Name, sessionVer.Age);
                }

                using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(30)))
                {
                    var dbaseVer1 = store.DatabaseCommands.Get(customer.Id);
                    Console.WriteLine("Database Version (AggressivelyCacheFor 30 mins):\n\t{0}: Name \"{1}\", Age={2}\n",
                                      dbaseVer1.Key, dbaseVer1.ToJson()["Name"], dbaseVer1.ToJson()["Age"]);
                }

                store.DatabaseCommands.Put(customer.Id, null,
                                           RavenJObject.FromObject(new Customer { Name = "Matt Warren", Age = 99 }),
                                           new RavenJObject());
                Console.WriteLine("Changed Database Version, Name = \"Matt Warren\", Age = 99\n");

                using (var session = store.OpenSession())
                {
                    using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(30)))
                    {
                        var newCustomer = session.Load<Customer>(customer.Id);
                        Console.WriteLine("Session Version (Without DisableAggressiveCaching):\n\t{0}: Name \"{1}\", Age={2}\n",
                                          newCustomer.Id, newCustomer.Name, newCustomer.Age);
                    }
                }

                using (var session = store.OpenSession())
                {
                    using (store.DisableAggressiveCaching())
                    {
                        var newCustomer = session.Load<Customer>(customer.Id);
                        Console.WriteLine("Session Version (DisableAggressiveCaching):\n\t{0}: Name \"{1}\", Age={2}\n",
                                          newCustomer.Id, newCustomer.Name, newCustomer.Age);
                    }
                }

                using (var session = store.OpenSession())
                {
                    using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(30)))
                    {
                        var newCustomer = session.Load<Customer>(customer.Id);
                        Console.WriteLine("Session Version (Without DisableAggressiveCaching):\n\t{0}: Name \"{1}\", Age={2}\n",
                                          newCustomer.Id, newCustomer.Name, newCustomer.Age);
                    }
                }

                Console.ReadLine();
            }
        }
开发者ID:kijanawoodard,项目名称:Raven-Issues,代码行数:71,代码来源:AggressiveCaching.cs


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