Exemplo n.º 1
0
        public static void ToStringAndTryParseTest(string tag, bool isWeak)
        {
            var headerValue = new TimedEntityTagHeaderValue(tag, isWeak);
            var s           = headerValue.ToString();
            TimedEntityTagHeaderValue headerValue2 = null;

            Assert.IsTrue(TimedEntityTagHeaderValue.TryParse(s, out headerValue2));
            Assert.AreEqual(headerValue.Tag, headerValue2.Tag);
            Assert.AreEqual(headerValue.LastModified.ToString(), headerValue2.LastModified.ToString());
            Assert.AreEqual(headerValue.IsWeak, headerValue2.IsWeak);
            Assert.AreEqual(headerValue.ToString(), headerValue2.ToString());
        }
Exemplo n.º 2
0
        // 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());
            }
        }
 public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
 {
     _cache.Put(key.HashBase64, eTag.ToString(), new[]
     {
         new DataCacheTag(key.ResourceUri),
         new DataCacheTag(key.RoutePattern),
     }, _regionName);
 }
        public void AddGetTest()
        {
            using (var store = new InMemoryEntityTagStore())
            {
                var cacheKey = new CacheKey(Url, new[] { "Accept" });

                var headerValue = new TimedEntityTagHeaderValue("\"abcdefghijkl\"");
                store.AddOrUpdate(cacheKey, headerValue);
                TimedEntityTagHeaderValue storedHeader;
                Assert.True(store.TryGetValue(cacheKey, out storedHeader));
                Assert.AreEqual(headerValue.ToString(), storedHeader.ToString());
            }
        }
Exemplo n.º 5
0
        public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
        {
            _database.StringSet(key.HashBase64, eTag.ToString(), _expiry);

            // resource
            var resourceKey = string.Format(ResourceFormat, key.ResourceUri);

            _database.SetAdd(resourceKey, key.HashBase64);
            if (_expiry.HasValue)
            {
                _database.KeyExpire(resourceKey, _expiry);
            }

            // routePattern
            var routePatternKey = string.Format(RoutePatternFormat, key.RoutePattern);

            _database.SetAdd(routePatternKey, key.HashBase64);
            if (_expiry.HasValue)
            {
                _database.KeyExpire(routePatternKey, _expiry);
            }
        }
Exemplo n.º 6
0
 public void AddOrUpdate(CacheKey key, TimedEntityTagHeaderValue eTag)
 {
     _database.StringSet(key.HashBase64, eTag.ToString(), Expiry);
     _database.SetAdd("ResourceUri_" + key.ResourceUri, key.HashBase64);
     _database.SetAdd("RoutePattern_" + key.RoutePattern, key.HashBase64);
 }