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


C# DocumentStore.AggressivelyCacheFor方法代码示例

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


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

示例1: LoadResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled

		public void LoadResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
			{
				store.Conventions.ShouldSaveChangesForceAggresiveCacheCheck = false;
				using (var session = store.OpenSession())
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{

					// make sure that object is cached
					using (var session = store.OpenSession())
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] {"users/1"});

						Assert.Equal("John", users[0].Name);
					}
					((DocumentStore)store).GetObserveChangesAndEvictItemsFromCacheTask().Wait();

					// change object
					using (var session = store.OpenSession())
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});
						session.SaveChanges();
					}


					Assert.True(SpinWait.SpinUntil(() =>store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					using (var session = store.OpenSession())
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("Adam", users[0].Name);
					}
				}
			}
		}
开发者ID:nzaugg,项目名称:ravendb,代码行数:53,代码来源:RavenDB_406.cs

示例2: ShouldServeFromCacheIfThereWasNoChange

		public void ShouldServeFromCacheIfThereWasNoChange()
		{
			using (var server = GetNewServer())
			using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
			{
				store.Conventions.ShouldSaveChangesForceAggresiveCacheCheck = false;
				using (var session = store.OpenSession())
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});

					session.SaveChanges();
				}
				WaitForIndexing(store);

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{
					// make sure that object is cached
					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] {"users/1"}).First();
						Assert.Equal("John", user.Name);
					}
					((DocumentStore)store).GetObserveChangesAndEvictItemsFromCacheTask().Wait();

					// change object
					using (var session = store.OpenSession())
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});

						session.SaveChanges();
					}
					WaitForIndexing(store);

					WaitForAllRequestsToComplete(server);
					server.Server.ResetNumberOfRequests();

					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] {"users/1"}).First(); // will create a request
						Assert.Equal("Adam", user.Name);
					}

					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] { "users/1" }).First(); // will be taken from a cache
						Assert.Equal("Adam", user.Name);
					}

					WaitForAllRequestsToComplete(server);
					
					Assert.Equal(1, server.Server.NumberOfRequests);
				}
			}
		}
开发者ID:nzaugg,项目名称:ravendb,代码行数:62,代码来源:RavenDB_406.cs

示例3: CacheClearingShouldTakeIntoAccountTenantDatabases

		public void CacheClearingShouldTakeIntoAccountTenantDatabases()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079"}.Initialize())
			{
				store.Conventions.ShouldSaveChangesForceAggresiveCacheCheck = false;

				store.DatabaseCommands.EnsureDatabaseExists("Northwind_1");
				store.DatabaseCommands.EnsureDatabaseExists("Northwind_2");

				using (var session = store.OpenSession("Northwind_1"))
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (var session = store.OpenSession("Northwind_2"))
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{
					// make sure that object is cached
					using (var session = store.OpenSession("Northwind_1"))
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}

					((DocumentStore)store).GetObserveChangesAndEvictItemsFromCacheTask().Wait();
					using (var session = store.OpenSession("Northwind_2"))
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}

					// change object on Northwind_1 ONLY
					using (var session = store.OpenSession("Northwind_1"))
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});
						session.SaveChanges();
					}


					Assert.True(SpinWait.SpinUntil(() => store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					using (var session = store.OpenSession("Northwind_1"))
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("Adam", users[0].Name);
					}

					using (var session = store.OpenSession("Northwind_2"))
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}
				}
			}
		}
开发者ID:nzaugg,项目名称:ravendb,代码行数:82,代码来源:RavenDB_406.cs

示例4: 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

示例5: QueryResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled

		public void QueryResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
			{
				new RavenDocumentsByEntityName().Execute(store);

				using (var session = store.OpenSession())
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				WaitForIndexing(store);

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{
					// make sure that object is cached
					using (var session = store.OpenSession())
					{
						var users = session.Query<User>()
							.ToList(); 

						Assert.Equal("John", users[0].Name);
					}

					// change object
					using (var session = store.OpenSession())
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});
						session.SaveChanges();
					}


					Assert.True(SpinWait.SpinUntil(() => store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					using (var session = store.OpenSession())
					{
						var users = session.Query<User>().ToList();

						Assert.Equal("Adam", users[0].Name);
					}
				}
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:53,代码来源:RavenDB_406.cs

示例6: ShouldServeFromCacheIfThereWasNoChange

		public void ShouldServeFromCacheIfThereWasNoChange()
		{
			using (var server = GetNewServer())
			using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
			{
				using (var session = store.OpenSession())
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});

					session.SaveChanges();
				}

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{
					// make sure that object is cached
					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] {"users/1"}).First();
						Assert.Equal("John", user.Name);
					}

					// change object
					using (var session = store.OpenSession())
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});

						session.SaveChanges();
					}

					Assert.True(SpinWait.SpinUntil(() => store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					server.Server.ResetNumberOfRequests();

					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] {"users/1"}).First(); // will create a request
						Assert.Equal("Adam", user.Name);
					}

					using (var session = store.OpenSession())
					{
						var user = session.Load<User>(new[] { "users/1" }).First(); // will be taken from a cache
						Assert.Equal("Adam", user.Name);
					}

					WaitForAllRequestsToComplete(server);

					Assert.Equal(1, server.Server.NumberOfRequests);
				}
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:59,代码来源:RavenDB_406.cs


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