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 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); } } } }
public void Clear() { using (var connection = new MongoEntiryStoreConnection(this.connectionString)) { connection.DocumentStore.RemoveAll(); } }
public bool TryRemove(CacheKey key) { int count; using (var connection = new MongoEntiryStoreConnection(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); }
public int RemoveAllByRoutePattern(string routePattern) { int count; using (var connection = new MongoEntiryStoreConnection(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); }
public bool TryGetValue(CacheKey key, out TimedEntityTagHeaderValue eTag) { eTag = null; using (var connection = new MongoEntiryStoreConnection(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); } }