EL 2.0 Preload Cache...

Topics: Caching Application Block
May 18, 2007 at 11:36 PM
I am having some issues preloading the EL cache. Pseudo code is below. Does anyone see any issues with this logic? If you need more information, please let me know. For some reason the item being called from cache is trying to load multiple times and my logic should prevent that. Also, when the refresh key I have set clears, I am getting multiple calls to my load caching method. Not sure how or why this is happening under heavy load.

     // **** WARNING... PSEUDO CODE ***
     private void LoadBigHeavyItem()
     {
          if(!Cache.Contains("BigHeavyCacheItem"))
          {
               if(!Cache.Contains("RefreshKey"))
               {
                    // load for first time so everyone gets to wait
                    RefreshCache();
               } else {
                    // we need to wait and call it again since the cache should already be refreshing
                    // this is only to handle initial load
                    Thread.Sleep(1000);
                    LoadBigHeavyCacheItem();
               }
          } else if(!Cache.Contains("RefreshKey")) {
               // if refresh key is gone we need to reload the cache while still serving
          
               // reset cache key so this if block doesn't get called again
               Cache.Add("RefreshKey"); // expire in 5 minutes please
 
               // kick off thread to reload cache.
               ThreadStart ThrdStart = new ThreadStart(Blah.RefreshCache);
               Thread Thrd = new Thread(ThrdStart);
               Thrd.Start();
          }
          // if we didn't hit the if blocks we are good to go.
     }
 
     private void RefreshCache()
     {
          Cache.Add("RefreshKey"); // expires in 5 minutes
          Cache.Add("BigHeavyCacheItem"); // expires in 10 minutes
     }
May 21, 2007 at 9:33 PM
Anyone have any ideas on the above? Sorry for the bump, but I am getting a little lost as to why this doesn't work.