public static void ClearExpireData(CacheKeyMapDescriptor cacheKeyMap) { Task.Factory.StartNew(() => { lock (cacheKeyMap) { MongoCollection <MongoDBCacheEntity> collection2 = DistributedCacheHelper.GetMongoDBCollection(cacheKeyMap.CacheId, cacheKeyMap.Cachelimit); var query = Query.And( Query.EQ("_id", cacheKeyMap.CacheId) ); WriteConcernResult res2 = collection2.Remove(query); string tableName = MongoDBCacheConfiguration.TableName + DateTime.Now.AddDays(-1).ToString("yyMMdd"); string expireDateTableName = MongoDBCacheConfiguration.TableName + "ByExpireDate"; if (collection2.Database.CollectionExists(tableName)) { collection2.Database.DropCollection(tableName); //清空前一天的数据集合 } if (collection2.Database.CollectionExists(expireDateTableName)) { query = Query.And( Query.LTE("ExpireDate", DateTime.Now) ); collection2.Database.GetCollection <MongoDBCacheEntity>(expireDateTableName).Remove(query); } CacheKeyMapManger.Instance.DeleteCacheKeyMap(CacheExpire.Expired); tableName = null; } }); }
public override void AddCacheKeyMap(CacheKeyMapDescriptor request) { MongoCollection <CacheKeyMapDescriptor> collection = DistributedCacheHelper.GetMongoDBCacheKeyMapCollection(); if (collection != null) { try { var query = Query.And(Query.EQ("CacheKey", request.CacheKey)); collection.Remove(query); } catch (Exception ex) { } WriteConcernResult res = collection.Save(request); if (request.Cachelimit != Cachelimit.Forever) { TimeSpan timespan = request.ExpireDate.Subtract(DateTime.Now); if (!collection.IndexExists(new IndexKeysBuilder().Ascending("ExpireDate"))) { collection.EnsureIndex(new IndexKeysBuilder().Ascending("ExpireDate"), IndexOptions.SetTimeToLive(timespan)); } } } }
/// <summary> /// 添加cachekeyap映射 /// </summary> /// <param name="request"></param> public override void AddCacheKeyMap(CacheKeyMapDescriptor request) { var item = mapList.ToList().Where(x => x.CacheKey == request.CacheKey).ToList(); item.ForEach(x => { DeleteCacheKeyMap(x); }); mapList.Add(request); }
public virtual List <CacheKeyMapDescriptor> GetCacheKeyMap(List <string> keys) { List <CacheKeyMapDescriptor> lst = new List <CacheKeyMapDescriptor>(); keys.ForEach(x => { CacheKeyMapDescriptor keymap = GetCacheKeyMap(x); if (keymap != null) { lst.Add(keymap); } }); return(lst); }
public override CacheKeyMapDescriptor GetCacheKeyMap(string key) { try { MongoCollection <CacheKeyMapDescriptor> collection = DistributedCacheHelper.GetMongoDBCacheKeyMapCollection(); var query = Query.And(Query.EQ("CacheKey", key)); CacheKeyMapDescriptor cacheKeyMap = collection.FindOne(query); if (cacheKeyMap == null) { return(cacheKeyMap); } return(cacheKeyMap); } catch (Exception ex) { return(null); } }
public override bool DeleteCacheKeyMap(CacheKeyMapDescriptor request) { MongoCollection <CacheKeyMapDescriptor> collection = DistributedCacheHelper.GetMongoDBCacheKeyMapCollection(); if (collection != null) { try { var query = Query.And(Query.EQ("CacheKey", request.CacheKey)); WriteConcernResult res = collection.Remove(query); if (res.Ok) { return(true); } return(false); } catch (Exception ex) { return(false); } } return(false); }
/// <summary> /// 删除cacheKeyMap映射 /// </summary> /// <param name="request"></param> /// <returns></returns> public override bool DeleteCacheKeyMap(CacheKeyMapDescriptor request) { return(mapList.TryTake(out request)); }
public override bool DeleteCacheKeyMap(CacheKeyMapDescriptor request) { return(_cacheKeyMap.DeleteCacheKeyMap(request)); }
public override void AddCacheKeyMap(CacheKeyMapDescriptor request) { _cacheKeyMap.AddCacheKeyMap(request); }
public abstract bool DeleteCacheKeyMap(CacheKeyMapDescriptor request);
public abstract void AddCacheKeyMap(CacheKeyMapDescriptor request);