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;
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 找到所在机子的连接字符串
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string ResolvePartition(object key)
        {
            string cacheId = (string)key;
            string prefix;
            string realId;

            if (!DistributedCacheHelper.ParseCacheID(cacheId, out prefix, out realId))
            {
                return(string.Empty);
            }

            return(MongoDBCacheConfiguration.CacheIdentityDBMap[prefix]);
        }