Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching Active Directory Data

In one of my applications, I am querying active directory to get a list of all users below a given user (using the "Direct Reports" thing). So basically, given the name of the person, it is looked up in AD, then the Direct Reports are read. But then for every direct report, the tool needs to check the direct reports of the direct reports. Or, more abstract: The Tool will use a person as the root of the tree and then walk down the complete tree to get the names of all the leaves (can be several hundred)

Now, my concern is obviously performance, as this needs to be done quite a few times. My idea is to manually cache that (essentially just put all the names in a long string and store that somewhere and update it once a day).

But I just wonder if there is a more elegant way to first get the information and then cache it, possibly using something in the System.DirectoryServices Namespace?

like image 624
Michael Stum Avatar asked Jan 24 '23 03:01

Michael Stum


2 Answers

In order to take control over the properties that you want to be cached you can call 'RefreshCache()' passing the properties that you want to hang around:

System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry();               

// Push the property values from AD back to cache.

entry.RefreshCache(new string[] {"cn", "www" });
like image 115
Erick Sgarbi Avatar answered Jan 26 '23 18:01

Erick Sgarbi


Active Directory is pretty efficient at storing information and the retrieval shouldn't be that much of a performance hit. If you are really intent on storing the names, you'll probably want to store them in some sort of a tree stucture, so you can see the relationships of all the people. Depending on how the number of people, you might as well pull all the information you need daily and then query all the requests against your cached copy.

like image 31
kemiller2002 Avatar answered Jan 26 '23 18:01

kemiller2002