Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HashTable cacheName
- {
- get{gettingHashTableFromApplication();}
- set{settingHashTableToApplication();}
- }
- if (HttpContext.Current.Cache[cacheName] == null)
- {
- //Checks if the hashtable contains the key so if not it will add it
- if (!cacheNames.Contains(cacheName))
- lock (cacheNames) // Lock the HashTable to add the key
- {
- if (!cacheNames.Contains(cacheName)) // check again the hashtable if contains the key
- {
- //cacheNames.Add(cacheName, new LockType()); // add the key with a LockType.
- cacheNames.Add(cacheName, cacheName); // add the key with a LockType.
- }
- }
- string locker = (string)cacheNames[cacheName]; // Get the corect LockType Object from the hashtable
- lock (locker) //lock the object so if another thread will try to load the ac to cache it will block it.
- {
- if (HttpContext.Current.Cache[cacheName] == null )
- {
- GetFromDB();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement