Advertisement
Arik27

my current code

Aug 9th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. HashTable cacheName
  2. {
  3. get{gettingHashTableFromApplication();}
  4. set{settingHashTableToApplication();}
  5. }
  6.  
  7. if (HttpContext.Current.Cache[cacheName] == null)
  8.         {
  9.             //Checks if the hashtable contains the key so if not it will add it
  10.             if (!cacheNames.Contains(cacheName))                   
  11.                lock (cacheNames) // Lock the HashTable to add the key
  12.                 {
  13.                     if (!cacheNames.Contains(cacheName)) // check again the hashtable if contains the key
  14.                     {
  15.                         //cacheNames.Add(cacheName, new LockType()); // add the key with a LockType.
  16.                         cacheNames.Add(cacheName, cacheName); // add the key with a LockType.
  17.                     }
  18.                 }
  19.            
  20. string locker = (string)cacheNames[cacheName]; // Get the corect LockType Object from the hashtable
  21.             lock (locker) //lock the object so if another thread will try to load the ac to cache  it will block it.
  22.             {
  23.                 if (HttpContext.Current.Cache[cacheName] == null )
  24.                 {
  25.                     GetFromDB();
  26.                 }
  27.             }
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement