使用OutputCache进行页面 缓存,但是遇到一个问题,
Action中缓存15秒,对于请求参数Name和Gender区分缓存
[OutputCache(Duration = 15, VaryByParam = "Name,Gender")]
public ActionResult Index(Employee e)
{
var employees = new[]{
new Employee(){ID=1,Name="ares",Gender="Male"},
new Employee(){ID=2,Name="bres",Gender="Male"},
new Employee(){ID=3,Name="btres",Gender="Male"},
new Employee(){ID=4,Name="arest",Gender="Male"},
new Employee(){ID=5,Name="cte",Gender="FMale"},
new Employee(){ID=6,Name="ctD",Gender="FMale"},
new Employee(){ID=3,Name="bUtres",Gender="FMale"}
};
List<Employee> lst = employees.ToList();
if (e != null)
{
if (!string.IsNullOrEmpty(e.Name))
lst = lst.FindAll(r => r.Name.Contains(e.Name));
if (!string.IsNullOrEmpty(e.Gender))
lst = lst.FindAll(r => r.Gender == e.Gender);
}
return View(new EmployeeSearchResultA { SearchPara = e, SearchResult = lst });
}
如图:请求http://localhost:11265/OutputCache?Name=&Gender=Male
下拉框中选择FMale,
点击查询,提交http://localhost:11265/OutputCache?Name=&Gender=FMale
按理来说这时候Gender参数值变了,应该重新请求,但是并不是预想的结果:
而是如图:
请求地址没有错误,但是页面结果却是之前请求Male时的结果,不知道这是啥原因?
哪位大神能够解惑?
[OutputCache(Duration = 15, VaryByParam = "Name,Gender")]
这里写错了,应该是,使用分号分隔多个参数
[OutputCache(Duration = 15, VaryByParam = "Name;Gender")]