public IEnumerable<MsgItem> Get(Guid? id) { Queue<MsgItem> msgs; try { msgs = cache.Get<Queue<MsgItem>>(MsgKey) ?? new Queue<MsgItem>(); } catch (Exception) { msgs = new Queue<MsgItem>(); } //判断当前请求Id在不在缓存对列中 //if (msgs.AsEnumerable<MsgItem>().Where(m => m.Id == id).Count() > 0) int index = (id == null) ? -1 : msgs.Select(m => m.Id).ToList().IndexOf(id.Value); if (index != -1) { return msgs.Skip(index + 1).Take(50 - index).AsEnumerable(); } //不在则返回缓存中最新的10条记录 else { int _startIndex = msgs.Count <= DefaultMsgLength ? 0 : msgs.Count - DefaultMsgLength; return msgs.Skip(_startIndex).Take(DefaultMsgLength).AsEnumerable(); } }