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


C# Common.CacheKey类代码示例

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


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

示例1: AddOrUpdate

        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);
            }
        }
开发者ID:jaredrussell,项目名称:Amikiri,代码行数:29,代码来源:RavenDbTagStore.cs

示例2: AddOrUpdate

        public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
        {
            TimedEntityTagHeaderValue test;
            if (!TryGetValue(key, out test))
            {
                var cacheKey = new PersistentCacheKey
                {
                    Hash = key.Hash,
                    RoutePattern = key.RoutePattern,
                    ETag = eTag.Tag,
                    LastModified = eTag.LastModified
                };

                using (var connection = new MongoEntiryStoreConnection(this.connectionString))
                {
                    connection.DocumentStore.Save(cacheKey);
                }
            }
            else
            {
                using (var connection = new MongoEntiryStoreConnection(this.connectionString))
                {
                    var cacheKey = connection.DocumentStore.AsQueryable().FirstOrDefault(x => x.Hash == key.Hash);
                    if (cacheKey != null)
                    {
                        cacheKey.ETag = eTag.Tag;
                        cacheKey.LastModified = eTag.LastModified;
                        connection.DocumentStore.Save(cacheKey);
                    }
                }
            }
        }
开发者ID:taliesins,项目名称:CacheCow,代码行数:32,代码来源:MongoDbEntityTagStore.cs

示例3: SendAsync

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            string uri = request.RequestUri.ToString();
            IEnumerable<string> varyHeaders;
            if(!VaryHeaderStore.TryGetValue(uri, out varyHeaders))
            {
                varyHeaders = DefaultVaryHeaders;
            }
            var cacheKey = new CacheKey(uri,
                request.Headers.Where(x=> varyHeaders.Any(y=> y.Equals(x.Key,
                    StringComparison.CurrentCultureIgnoreCase)))
                    .SelectMany(z=>z.Value)
                );

            HttpResponseMessage response;
            if(_cacheStore.TryGetValue(cacheKey, out response))
            {
                response.RequestMessage = request;
                var taskCompletionSource = new TaskCompletionSource<HttpResponseMessage>();
                taskCompletionSource.SetResult(response);
                return taskCompletionSource.Task;
            }
            // TODO: ..... REST)

            return base.SendAsync(request, cancellationToken);
        }
开发者ID:sayedihashimi,项目名称:CacheCow,代码行数:26,代码来源:CachingHandler.cs

示例4: AddOrUpdate

        public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
        {
            TimedEntityTagHeaderValue test;
            if (!TryGetValue(key, out test))
            {
                var cacheKey = new PersistentCacheKey()
                {
                    Hash = key.Hash,
                    RoutePattern = key.RoutePattern,
                    ETag = eTag.Tag,
                    LastModified = eTag.LastModified
                };
                using (var session = _documentStore.OpenSession())
                {
                    session.Store(cacheKey);
                    session.SaveChanges();
                }

            }
            else
            {
                using (var session = _documentStore.OpenSession())
                {
                    var cacheKey =
                        session.Query<PersistentCacheKey>()
                        .Customize(x => x.WaitForNonStaleResults())
                        .FirstOrDefault(x => x.Hash == key.Hash);
                    cacheKey.ETag = eTag.Tag;
                    cacheKey.LastModified = eTag.LastModified;
                    session.Store(cacheKey);
                    session.SaveChanges();
                }
            }
        }
开发者ID:taliesins,项目名称:CacheCow,代码行数:34,代码来源:RavenDbEntityTagStore.cs

示例5: AddTest

        public void AddTest()
        {
            var cacheKey = new CacheKey("/api/Cars", new[] { "1234", "abcdef" });
            var documentStore = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            }.Initialize();

            new RavenDocumentsByEntityName().Execute(documentStore);

            var store = new RavenDbEntityTagStore(documentStore);
            var value = new TimedEntityTagHeaderValue("\"abcdef1234\"") { LastModified = DateTime.Now };

            // first remove them
            store.RemoveAllByRoutePattern(cacheKey.RoutePattern);

            // add
            store.AddOrUpdate(cacheKey, value);

            // get
            TimedEntityTagHeaderValue dbValue;
            store.TryGetValue(cacheKey, out dbValue);

            Assert.AreEqual(value.Tag, dbValue.Tag);
            Assert.AreEqual(value.LastModified.ToString(), dbValue.LastModified.ToString());
        }
开发者ID:taliesins,项目名称:CacheCow,代码行数:26,代码来源:IntegrationTests.cs

示例6: TryGetValue

		public bool TryGetValue(CacheKey key, out TimedEntityTagHeaderValue eTag)
		{
			eTag = null;
			using (var connection = new SqlConnection(this._connectionString))
			using (var command = new SqlCommand())
			{
				connection.Open();
				command.Connection = connection;
				command.CommandText = this.GetStoredProcedureName(StoredProcedureNames.GetCache);
				command.CommandType = CommandType.StoredProcedure;
				command.Parameters.AddWithValue(ColumnNames.CacheKeyHash, key.Hash);

				using (var reader = command.ExecuteReader( CommandBehavior.CloseConnection))
				{
					if(!reader.HasRows)
						return false;

					reader.Read(); // there must be only one record

					eTag= new TimedEntityTagHeaderValue((string) reader[ColumnNames.ETag])
					      	{
					      		LastModified = DateTime.SpecifyKind((DateTime)reader[ColumnNames.LastModified], DateTimeKind.Utc)
					      	};
					return true;
				}
			}
		}
开发者ID:yyf919,项目名称:CacheCow,代码行数:27,代码来源:SqlServerEntityTagStore.cs

示例7: AddOrUpdate

        // TODO: !!! routePattern implementation needs to be changed to Cas
        public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
        {
            // add item
            _memcachedClient.ExecuteStore(StoreMode.Set, key.HashBase64, eTag.ToString());

            // add route pattern if not there
            string keyForRoutePattern = GetKeyForRoutePattern(key.RoutePattern);
            string keyForResourceUri = GetKeyForResourceUri(key.ResourceUri);
            var routePatternEntries = GetRoutePatternEntries(key.RoutePattern);
            var resourceUriEntries = GetResourceUriEntries(key.ResourceUri);

            if (!routePatternEntries.Contains(key.HashBase64))
            {
                var bytes = new List<byte>();
                foreach (var routePatternEntry in routePatternEntries)
                {
                    bytes.AddRange(new LengthedPrefixedString(routePatternEntry).ToByteArray());
                }
                bytes.AddRange(new LengthedPrefixedString(key.HashBase64).ToByteArray());
                _memcachedClient.ExecuteStore(StoreMode.Set, keyForRoutePattern, bytes.ToArray());

            }

            if (!resourceUriEntries.Contains(key.HashBase64))
            {
                var bytes = new List<byte>();
                foreach (var routePatternEntry in resourceUriEntries)
                {
                    bytes.AddRange(new LengthedPrefixedString(routePatternEntry).ToByteArray());
                }
                bytes.AddRange(new LengthedPrefixedString(key.HashBase64).ToByteArray());
                _memcachedClient.ExecuteStore(StoreMode.Set, keyForResourceUri, bytes.ToArray());

            }
        }
开发者ID:Nangal,项目名称:CacheCow,代码行数:36,代码来源:MemcachedEntityTagStore.cs

示例8: AddOrUpdate

        public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
        {
            // removing reference to request so that the request can get GCed
            response.RequestMessage = null;

            _responseCache.AddOrUpdate(key, response, (ky, resp) => resp);
        }
开发者ID:sayedihashimi,项目名称:CacheCow,代码行数:7,代码来源:InMemoryCacheStore.cs

示例9: UpdateTest

		public void UpdateTest()
		{
			var cacheKey = new CacheKey("/api/Cars", new[] { "1234", "abcdef" });
			var store = new SqlServerEntityTagStore();
			var value = new TimedEntityTagHeaderValue("\"abcdef1234\"") { LastModified = DateTime.Now };


			// first remove them
			store.RemoveAllByRoutePattern(cacheKey.RoutePattern);

			// add
			store.AddOrUpdate(cacheKey, value);

			// get
			TimedEntityTagHeaderValue dbValue;
			store.TryGetValue(cacheKey, out dbValue);

			value.LastModified = DateTime.Now.AddDays(-1);

			// update
			store.AddOrUpdate(cacheKey, value);

			// get
			TimedEntityTagHeaderValue dbValue2;
			store.TryGetValue(cacheKey, out dbValue2);

			Assert.AreEqual(dbValue.Tag, dbValue2.Tag);
			Assert.Greater(dbValue.LastModified, dbValue2.LastModified);
			Console.WriteLine(dbValue2.Tag);
			Console.WriteLine(dbValue2.LastModified);
		}
开发者ID:yyf919,项目名称:CacheCow,代码行数:31,代码来源:IntegrationTests.cs

示例10: TestCacheInvalidationForPost

		public static void TestCacheInvalidationForPost(string method)
		{
		    const string relatedUrl = "http://api/SomeLocationUrl/";
			// setup
			var locationUrl = new Uri(relatedUrl);
			var mocks = new MockRepository();
			var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
			string routePattern = "http://myserver/api/stuffs/*";
			var entityTagStore = mocks.StrictMock<IEntityTagStore>();

			var cachingHandler = new CachingHandler(new HttpConfiguration(), entityTagStore)
			{
				
			};
			var entityTagKey = new CacheKey(TestUrl, new string[0], routePattern);
			var response = new HttpResponseMessage();
			response.Headers.Location = locationUrl;
			var invalidateCacheForPost = cachingHandler.PostInvalidationRule(entityTagKey, request, response);
			if(method == "POST")
			{
                entityTagStore.Expect(x => x.RemoveAllByRoutePattern("/SomeLocationUrl/")).Return(1);				
			}
			mocks.ReplayAll();

			// run
			invalidateCacheForPost();

			// verify
			mocks.VerifyAll();

			
		}
开发者ID:yyf919,项目名称:CacheCow,代码行数:32,代码来源:CachingHandlerTests.cs

示例11: AddCaching

        public static void AddCaching(string method,
			bool existsInStore,
			bool addVaryHeader,
			bool addLastModifiedHeader,
			bool alreadyHasLastModified,
			string[] varyByHeader)
        {
            // setup
            var mocks = new MockRepository();
            var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
            request.Headers.Add(HttpHeaderNames.Accept, "text/xml");
            request.Headers.Add(HttpHeaderNames.AcceptLanguage, "en-GB");
            var entityTagStore = mocks.StrictMock<IEntityTagStore>();
            var entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"");
            var cachingHandler = new CachingHandler(entityTagStore, varyByHeader)
            {
                AddLastModifiedHeader = addLastModifiedHeader,
                AddVaryHeader = addVaryHeader,
                ETagValueGenerator = (x,y) => entityTagHeaderValue
            };

            var entityTagKey = new CacheKey(TestUrl, new[] {"text/xml", "en-GB"}, TestUrl + "/*");

            entityTagStore.Expect(x => x.TryGetValue(Arg<CacheKey>.Matches(etg => etg.ResourceUri == TestUrl),
                out Arg<TimedEntityTagHeaderValue>.Out(entityTagHeaderValue).Dummy)).Return(existsInStore);

            if (!existsInStore)
            {
                entityTagStore.Expect(
                    x => x.AddOrUpdate(Arg<CacheKey>.Matches(etk => etk == entityTagKey),
                        Arg<TimedEntityTagHeaderValue>.Matches(ethv => ethv.Tag == entityTagHeaderValue.Tag)));
            }

            var response = new HttpResponseMessage();
            response.Content = new ByteArrayContent(new byte[0]);
            if (alreadyHasLastModified)
                response.Content.Headers.Add(HttpHeaderNames.LastModified, DateTimeOffset.Now.ToString("r"));

            var cachingContinuation = cachingHandler.AddCaching(entityTagKey, request, response, request.Headers);
            mocks.ReplayAll();

            // run
            cachingContinuation();

            // verify

            // test kast modified only if it is GET and PUT
            if (addLastModifiedHeader && method.IsIn("PUT", "GET"))
            {
                Assert.That(response.Content.Headers.Any(x => x.Key == HttpHeaderNames.LastModified),
                    "LastModified does not exist");
            }
            if (!addLastModifiedHeader && !alreadyHasLastModified)
            {
                Assert.That(!response.Content.Headers.Any(x => x.Key == HttpHeaderNames.LastModified),
                    "LastModified exists");
            }
            mocks.VerifyAll();
        }
开发者ID:sh54,项目名称:CacheCow,代码行数:59,代码来源:CachingHandlerTests.cs

示例12: AddOrUpdate

		public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
		{
			var memoryStream = new MemoryStream();
		    Task.Factory.StartNew(() => _serializer.SerializeAsync(response.ToTask(), memoryStream).Wait()).Wait(); // offloading
		    memoryStream.Position = 0;
		    var data = memoryStream.ToArray();
		    _database.StringSet(key.HashBase64, data);
		}
开发者ID:yyf919,项目名称:CacheCow,代码行数:8,代码来源:RedisStore.cs

示例13: AddOrUpdate

 public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
 {
     cache.Put(key.HashBase64, eTag.ToString(), new[]
                                        {
                                            new DataCacheTag(key.ResourceUri),
                                            new DataCacheTag(key.RoutePattern),
                                        }, CacheRegion);
 }
开发者ID:tugberkugurlu,项目名称:CacheCow,代码行数:8,代码来源:AzureCachingEntityTagStore.cs

示例14: AddOrUpdate

        public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
        {
            var ms = new MemoryStream();

            this.serializer.SerializeAsync(TaskHelpers.FromResult(response), ms)
                .Wait();

            this.cache.Add(key.HashBase64, ms.ToArray(), CacheRegion);
        }
开发者ID:tugberkugurlu,项目名称:CacheCow,代码行数:9,代码来源:AzureCacheStore.cs

示例15: AddOrUpdate

        public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
        {
            var ms = new MemoryStream();

            _serializer.SerializeAsync(TaskHelpers.FromResult(response), ms)
                .Wait();

            _memcachedClient.ExecuteStore(StoreMode.Set, key.HashBase64, ms.ToArray());
        }
开发者ID:beyond-code-github,项目名称:CacheCow,代码行数:9,代码来源:MemcachedStore.cs


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