【发布时间】:2015-03-13 18:03:12
【问题描述】:
我希望通过使用一些缓存之王来提高性能。 例如,用户登录并访问约会系统,我想缓存此数据,从缓存中查询此数据,然后在添加新约会时更新缓存
例如,我正在写这个,但我认为这是应用程序缓存而不是会话(不希望其他用户看到其他人的数据)
public IEnumerable<ScheduledItem> GetCache(bool reload, DateTime start, DateTime end, Account account)
{
if (System.Web.HttpContext.Current.Cache["ScheduleData"] == null)
{
var model = _eventService.FindAllEventsForAccountId(account.Id, start.Date, end.Date)
.Where(IsAppointmentNotCancelled)
.Select(a => new Models.ScheduledItem()
{
id = a.Id,
start = a.StartTime.ToString("H:mm:ss").Length < 8 ? string.Format(a.StartTime.ToString("yyyy-MM-dd {0}H:mm:ss"), 0) : a.StartTime.ToString("yyyy-MM-dd H:mm:ss"),
end = a.EndTime.ToString("H:mm:ss").Length < 8 ? string.Format(a.EndTime.ToString("yyyy-MM-dd {0}H:mm:ss"), 0) : a.EndTime.ToString("yyyy-MM-dd H:mm:ss"),
backgroundColor = GetColour(a),
title = GetTitle(a, account),
textColor = "#fff",
AppointmentType = GetType(a),
resourceId = GetResource(a)
}).ToList();
return model;
}
return null;
}
任何指针,例子都会很棒
【问题讨论】:
-
你看过stackoverflow.com/questions/343899/…吗?然后还有 OutputCacheAttribute,它使用各种设置缓存操作的输出。恕我直言,您不应该重新发明这样的东西。
-
是的,看到了,这似乎是更新的方法? msdn.microsoft.com/en-us/library/vstudio/…
-
codethatway.wordpress.com/2014/11/18/… 你介意经历一下吗,可能对你有帮助
标签: c# .net asp.net-mvc session caching