Example #1
0
		public void SecondLevelCacheWithSingleCacheableFuture()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				User user = new User() { Name="test" };
				s.Save(user);
				tx.Commit();
			}

			using (ISession s = OpenSession())
			{
				// Query results should be cached
				User user =
					s.CreateCriteria<User>()
						.Add(Restrictions.NaturalId().Set("Name", "test"))
						.SetCacheable(true)
						.FutureValue<User>()
						.Value;

				Assert.That(user, Is.Not.Null);

				DeleteObjectsOutsideCache(s);
			}

			using (ISession s = OpenSession())
			{
				User user =
					s.CreateCriteria<User>()
						.Add(Restrictions.NaturalId().Set("Name", "test"))
						.SetCacheable(true)
						.FutureValue<User>()
						.Value;

				Assert.That(user, Is.Not.Null,
					"entity not retrieved from cache");
			}
		}
Example #2
0
		public void SecondLevelCacheWithMixedCacheRegionsFuture()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				User user = new User() { Name="test" };
				s.Save(user);
				tx.Commit();
			}

			using (ISession s = OpenSession())
			{
				// cacheable Future, not evaluated yet
				IFutureValue<User> userFuture =
					s.CreateCriteria<User>()
						.Add(Restrictions.NaturalId().Set("Name", "test"))
						.SetCacheable(true)
						.SetCacheRegion("region1")
						.FutureValue<User>();

				// different cache-region causes batch to be non-cacheable
				int count =
					s.CreateCriteria<User>()
						.SetProjection(Projections.RowCount())
						.SetCacheable(true)
						.SetCacheRegion("region2")
						.FutureValue<int>()
						.Value;

				Assert.That(userFuture.Value, Is.Not.Null);
				Assert.That(count, Is.EqualTo(1));

				DeleteObjectsOutsideCache(s);
			}

			using (ISession s = OpenSession())
			{
				IFutureValue<User> userFuture =
					s.CreateCriteria<User>()
						.Add(Restrictions.NaturalId().Set("Name", "test"))
						.SetCacheable(true)
						.SetCacheRegion("region1")
						.FutureValue<User>();

				int count =
					s.CreateCriteria<User>()
						.SetProjection(Projections.RowCount())
						.SetCacheable(true)
						.SetCacheRegion("region2")
						.FutureValue<int>()
						.Value;

				Assert.That(userFuture.Value, Is.Null,
					"query results should not come from cache");
			}
		}