2013-07-18 31 views
0

我有retrive當前的Active Directory用戶以下資源庫方法: -如何緩存模型庫導致

public List<DomainContext> GetADUsers(string term=null) 
{ 
    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(); 



     foreach (Principal p in searchResults) 
     { 
      if (term == null || p.SamAccountName.ToString().ToUpper().StartsWith(term.ToUpper())) 
      { 
      DomainContext dc = new DomainContext(); 
      dc.DisplayName = p.DisplayName; 
      dc.UserPrincipalName = p.UserPrincipalName; 
      dc.Name = p.Name; 
      dc.SamAccountName = p.SamAccountName ; 
      dc.DistinguishedName =  p.DistinguishedName; 

      results.Add(dc); 

     }} 
    } 
    return results; 
} 

因此,作爲該廣告的用戶,不經常變化,所以我需要緩存的結果這種方法約2小時。所以對此方法的任何調用都不應該調用Active Directory?我實際上試圖實現與Action方法中定義的[OutputCache]相同的邏輯。 Regards

+2

提起'[的OutputCache]',爲什麼不能用它來裝飾,返回你的Active Directory用戶的行動? – haim770

+0

沒有指定的操作方法返回活動目錄。它是Repository Model類中的一個方法。 –

回答