Esempio 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,
                    ETag         = eTag.Tag,
                    LastModified = eTag.LastModified,
                    ResourceUri  = key.ResourceUri
                };

                using (var connection = new MongoEntityStoreConnection(this.connectionString))
                {
                    connection.DocumentStore.Save(cacheKey);
                }
            }
            else
            {
                using (var connection = new MongoEntityStoreConnection(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);
                    }
                }
            }
        }
Esempio n. 2
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,
					ETag = eTag.Tag,
					LastModified = eTag.LastModified,
                    ResourceUri = key.ResourceUri
				};

				using (var connection = new MongoEntityStoreConnection(this.connectionString))
				{
					connection.DocumentStore.Save(cacheKey);
				}
			}
			else
			{
				using (var connection = new MongoEntityStoreConnection(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);
					}
				}
			}
		}
Esempio n. 3
0
 public void Clear()
 {
     using (var connection = new MongoEntityStoreConnection(this.connectionString))
     {
         connection.DocumentStore.RemoveAll();
     }
 }
Esempio n. 4
0
        public bool TryRemove(CacheKey key)
        {
            int count;

            using (var connection = new MongoEntityStoreConnection(this.connectionString))
            {
                var persistentCacheKeys = connection.DocumentStore.AsQueryable().Where(p => p.Hash == key.Hash);
                count = persistentCacheKeys.Count();
                foreach (var query in persistentCacheKeys.Select(cacheKey => Query.EQ("_id", ObjectId.Parse(cacheKey.Id))))
                {
                    connection.DocumentStore.Remove(query);
                }
            }

            return(count > 0);
        }
Esempio n. 5
0
		public bool TryGetValue(CacheKey key, out TimedEntityTagHeaderValue eTag)
		{
			eTag = null;

			using (var connection = new MongoEntityStoreConnection(this.connectionString))
			{
				var cacheKey = connection.DocumentStore.AsQueryable().FirstOrDefault(x => x.Hash == key.Hash);
				if (null == cacheKey)
					return false;

				eTag = new TimedEntityTagHeaderValue(cacheKey.ETag)
				{
					LastModified = cacheKey.LastModified
				};

				return true;
			}
		}
Esempio n. 6
0
        public int RemoveAllByRoutePattern(string routePattern)
        {
            int count;

            using (var connection = new MongoEntityStoreConnection(this.connectionString))
            {
                var persistentCacheKeys = connection.DocumentStore.AsQueryable().Where(p => p.RoutePattern == routePattern);

                count = persistentCacheKeys.Count();

                foreach (var query in persistentCacheKeys.Select(cacheKey => Query.EQ("_id", ObjectId.Parse(cacheKey.Id))))
                {
                    connection.DocumentStore.Remove(query);
                }
            }

            return(count);
        }
Esempio n. 7
0
        public bool TryGetValue(CacheKey key, out TimedEntityTagHeaderValue eTag)
        {
            eTag = null;

            using (var connection = new MongoEntityStoreConnection(this.connectionString))
            {
                var cacheKey = connection.DocumentStore.AsQueryable().FirstOrDefault(x => x.Hash == key.Hash);
                if (null == cacheKey)
                {
                    return(false);
                }

                eTag = new TimedEntityTagHeaderValue(cacheKey.ETag)
                {
                    LastModified = cacheKey.LastModified
                };

                return(true);
            }
        }
Esempio n. 8
0
	    public int RemoveResource(string resourceUri)
	    {
            int count;
            using (var connection = new MongoEntityStoreConnection(this.connectionString))
            {
                var persistentCacheKeys = connection.DocumentStore.AsQueryable()
                    .Where(p => p.ResourceUri == resourceUri);

                count = persistentCacheKeys.Count();

                foreach (var query in persistentCacheKeys
                    .Select(cacheKey => Query.EQ("_id", ObjectId.Parse(cacheKey.Id))))
                {
                    connection.DocumentStore.Remove(query);
                }
            }

            return count;
	    }
Esempio n. 9
0
		public void Clear()
		{
			using (var connection = new MongoEntityStoreConnection(this.connectionString))
			{
				connection.DocumentStore.RemoveAll();
			}
		}
Esempio n. 10
0
	    public bool TryRemove(CacheKey key)
		{
			int count;
			using (var connection = new MongoEntityStoreConnection(this.connectionString))
			{
				var persistentCacheKeys = connection.DocumentStore.AsQueryable().Where(p => p.Hash == key.Hash);
				count = persistentCacheKeys.Count();
				foreach (var query in persistentCacheKeys.Select(cacheKey => Query.EQ("_id", ObjectId.Parse(cacheKey.Id))))
				{
					connection.DocumentStore.Remove(query);
				}
			}

			return count > 0;
		}