Ejemplo n.º 1
0
        public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
        {
            TimedEntityTagHeaderValue test;
            if (!TryGetValue(key, out test))
            {
                var cacheKey = new PersistentCacheKey
                {
                    Hash = key.Hash,
                    RoutePattern = key.RoutePattern,
                    CustomEtag = eTag.Tag,
                    LastModified = eTag.LastModified,
                    ResourceUri = key.ResourceUri
                };

                _session.Store(cacheKey);
            }
            else
            {
                var cacheKey = _session.Query<PersistentCacheKey>()
                    .Customize(x => x.WaitForNonStaleResults())
                    .FirstOrDefault(x => x.Hash == key.Hash);

                cacheKey.CustomEtag = eTag.Tag;
                cacheKey.LastModified = eTag.LastModified;
                cacheKey.ResourceUri = key.ResourceUri;
                cacheKey.RoutePattern = key.RoutePattern;
                _session.Store(cacheKey);
            }
        }
Ejemplo n.º 2
0
		public void AddTest()
		{
			// want a green test? comment this	
			using (var documentStore = NewDocumentStore())
			{
				documentStore.Initialize();
				new RavenDocumentsByEntityName().Execute(documentStore);


				// want a green test? uncomment this	
				//var documentStore = new DocumentStore() {
				//	Url = "http://localhost:8082/databases/entitytagstore"
				//}.Initialize();

				byte[] hash;

				using (var sha1 = new SHA1CryptoServiceProvider())
				{
					hash = sha1.ComputeHash(Encoding.UTF8.GetBytes("/api/Cars"));
				}

				var persistentCacheKey = new PersistentCacheKey()
				{
					ETag = "\"abcdef1234\"",
					Hash = hash,
					LastModified = DateTime.Now,
					RoutePattern = "/api/Cars"
				};

				using (var session = documentStore.OpenSession())
				{
					session.Store(persistentCacheKey);
					session.SaveChanges();
				}
				PersistentCacheKey key;
				using (var session = documentStore.OpenSession())
				{
					key = session.Query<PersistentCacheKey>()
						.Customize(x => x.WaitForNonStaleResultsAsOfNow())
						.FirstOrDefault(p => p.Hash == hash);
				}

				Assert.NotNull(key);
			}
		}
Ejemplo n.º 3
0
        public void AddTest()
        {
            // want a green test? comment this
            using (var documentStore = NewDocumentStore())
            {
                documentStore.Initialize();
                new RavenDocumentsByEntityName().Execute(documentStore);


                // want a green test? uncomment this
                //var documentStore = new DocumentStore() {
                //	Url = "http://localhost:8082/databases/entitytagstore"
                //}.Initialize();

                byte[] hash;

                using (var sha1 = new SHA1CryptoServiceProvider())
                {
                    hash = sha1.ComputeHash(Encoding.UTF8.GetBytes("/api/Cars"));
                }

                var persistentCacheKey = new PersistentCacheKey()
                {
                    ETag         = "\"abcdef1234\"",
                    Hash         = hash,
                    LastModified = DateTime.Now,
                    RoutePattern = "/api/Cars"
                };

                using (var session = documentStore.OpenSession())
                {
                    session.Store(persistentCacheKey);
                    session.SaveChanges();
                }
                PersistentCacheKey key;
                using (var session = documentStore.OpenSession())
                {
                    key = session.Query <PersistentCacheKey>()
                          .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                          .FirstOrDefault(p => p.Hash == hash);
                }

                Assert.NotNull(key);
            }
        }