コード例 #1
0
        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <param name="pids"></param>
        /// <returns></returns>
        public async Task <bool> RemoveCache(List <string> pids)
        {
            var result = false;

            try
            {
                using (var client = new Service.BaoYang.CacheClient())
                {
                    var batchSize = 200;
                    for (var i = 0; i < Math.Ceiling(pids.Count * 1.0 / batchSize); i++) //分批清除缓存 每批次200个
                    {
                        var clientResult = await client.RemoveByTypeAsync
                                               ("BatteryCouponPriceDisplay", pids.Skip(i *batchSize).Take(batchSize).ToList());

                        result = clientResult.Success;
                        if (!result && clientResult.Exception != null)
                        {
                            Logger.Warn("调用BaoYang服务RemoveByTypeAsync失败", clientResult.Exception);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("RemoveCache", ex);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 根据type和data清除缓存
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task <bool> RemoveCacheByTypeAsync(string type, List <string> data)
        {
            using (var cilent = new Service.BaoYang.CacheClient())
            {
                var cacheResult = await cilent.RemoveByTypeAsync(type, data);

                return(cacheResult.Success);
            }
        }