我读过的所有示例都将 OutputCache 应用于控制器操作方法。但现在我有一个存储库方法,它检索 Active Directory 用户。所以我想缓存这个模型类,例如:
[OutputCache(CacheProfile = "long", Location = OutputCacheLocation.Server, VaryByParam = "term")]
public List<DomainContext> GetADUsers(string term)
{
List<DomainContext> results = new List<DomainContext>();
using (var context = new PrincipalContext(ContextType.Domain, "WIN-SPDEV"))
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
var searchResults = searcher.FindAll();
为了实现这一点,我必须在我的存储库模型类中包含以下内容:-
using System.Web.Mvc;
using System.Web.UI;
所以添加缓存设置并包含`System.web.mvc + system.Web.UI,插入存储库模型类是错误的还是不好的做法?