Reputation: 1
I have the following Repository method which retrive the current Active Directory users :-
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;
}
So as the AD users , does not change frequently so i need to cache the result of this method for around 2 hours. so any call to this method should not call the Active Directory ? I am actually trying to implement the same logic as for the [OutputCache]
defined on the Action methods.
Regards
Upvotes: 0
Views: 144
Reputation: 3441
As it is a bit hard to code the whole solution for you I will point to the Microsoft Patterns & Practices Caching Application Block.
Read the documentation, the implementation you need should be pretty straightforward.
I hope it helps!
Edit:
I found a more up to date documentation: http://msdn.microsoft.com/en-us/library/ff953179%28v=pandp.50%29.aspx
Upvotes: 1