Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. strange issue with cache application block (ENT LIB 5)

strange issue with cache application block (ENT LIB 5)

Scheduled Pinned Locked Moved ASP.NET
helpcsharplinqwindows-adminperformance
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Luca Dominici
    wrote on last edited by
    #1

    Hi all, I am relatively new to Caching application block, so my problem can be very trivial. But I don't get it. So there is this complex application (in production enviroment) that I have rewritten to use cache. my framework is not so easy to describe, however: every service class (in the logic tier) has a father class that define the cache (static, so application wide)

    SmallObjectCache = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>("SmallObjectCache");

    I have written some classes to manage my cache: I use for single objects and for list of object (Read operation and GetAll operation)

    protected virtual void CacheAddData(DomainObject domainObject)
    {
    if (domainObject != null)
    {
    CacheDictionary[this.GetType().FullName].Add(this.GetType().FullName + "_" + domainObject.GetId(), domainObject);

        List<DomainObject> cachedObj = CacheGetAllData();
        if (cachedObj != null && cachedObj.Count > 0)
        {
            int idx = -1;
            try
            {
                idx = cachedObj.FindIndex(a => a.GetId() == domainObject.GetId());
                cachedObj.RemoveAll(a => a.GetId() == domainObject.GetId());
            }
            catch (NullReferenceException)
            {
                BusinessFacade.ApplicationLogger.Write("INFO: Cache: Linq exception", Category.General, Priority.Normal, 1, System.Diagnostics.TraceEventType.Information);
            }
    
            if (idx >= 0)
                cachedObj.Insert(idx, domainObject);
            else
                cachedObj.Add(domainObject);
            CacheAddAllData(cachedObj);
        }
    }
    

    }

    So what the above do is to add an item in cache and if exist a list of that objects retrive it and add/insert in the right position the item. Now the bug: Everything is running fine. 100+ people use the system without a glitch. BUT sometime, near middle of the day, one or two people report a nullreference exception, especially in this code:

    List<Utente> decoratori = GetAll().Cast<Utente>().ToList().Where<Utente>(u => u.Ruolo.IsDecoratore()).ToList();

    the where iterator crash stating that object is null (I do checks before the only null objects can be the "Ruolo") Now this is the issue: the same user with everyting unchanged became without an attribute (non deterministic). Recycling the IIS memory fix the issue (so is not a reproducible issue).

    P J 2 Replies Last reply
    0
    • L Luca Dominici

      Hi all, I am relatively new to Caching application block, so my problem can be very trivial. But I don't get it. So there is this complex application (in production enviroment) that I have rewritten to use cache. my framework is not so easy to describe, however: every service class (in the logic tier) has a father class that define the cache (static, so application wide)

      SmallObjectCache = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>("SmallObjectCache");

      I have written some classes to manage my cache: I use for single objects and for list of object (Read operation and GetAll operation)

      protected virtual void CacheAddData(DomainObject domainObject)
      {
      if (domainObject != null)
      {
      CacheDictionary[this.GetType().FullName].Add(this.GetType().FullName + "_" + domainObject.GetId(), domainObject);

          List<DomainObject> cachedObj = CacheGetAllData();
          if (cachedObj != null && cachedObj.Count > 0)
          {
              int idx = -1;
              try
              {
                  idx = cachedObj.FindIndex(a => a.GetId() == domainObject.GetId());
                  cachedObj.RemoveAll(a => a.GetId() == domainObject.GetId());
              }
              catch (NullReferenceException)
              {
                  BusinessFacade.ApplicationLogger.Write("INFO: Cache: Linq exception", Category.General, Priority.Normal, 1, System.Diagnostics.TraceEventType.Information);
              }
      
              if (idx >= 0)
                  cachedObj.Insert(idx, domainObject);
              else
                  cachedObj.Add(domainObject);
              CacheAddAllData(cachedObj);
          }
      }
      

      }

      So what the above do is to add an item in cache and if exist a list of that objects retrive it and add/insert in the right position the item. Now the bug: Everything is running fine. 100+ people use the system without a glitch. BUT sometime, near middle of the day, one or two people report a nullreference exception, especially in this code:

      List<Utente> decoratori = GetAll().Cast<Utente>().ToList().Where<Utente>(u => u.Ruolo.IsDecoratore()).ToList();

      the where iterator crash stating that object is null (I do checks before the only null objects can be the "Ruolo") Now this is the issue: the same user with everyting unchanged became without an attribute (non deterministic). Recycling the IIS memory fix the issue (so is not a reproducible issue).

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      The thing about a cache is that you can't guarantee that it still holds data. A typical pattern with a cache is to attempt to retrieve an item from the cache, and if nothing is returned, the cache is refreshed with the data and then the item is returned. It sounds as though this is your issue. Basically, something you are trying to retrieve is no longer present in the cache, so you recycle IIS which causes you to repopulate the cache because you go through your normal start up processes. The only thing you can do to fix this is to add the functionality to check and reload the items.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      1 Reply Last reply
      0
      • L Luca Dominici

        Hi all, I am relatively new to Caching application block, so my problem can be very trivial. But I don't get it. So there is this complex application (in production enviroment) that I have rewritten to use cache. my framework is not so easy to describe, however: every service class (in the logic tier) has a father class that define the cache (static, so application wide)

        SmallObjectCache = EnterpriseLibraryContainer.Current.GetInstance<ICacheManager>("SmallObjectCache");

        I have written some classes to manage my cache: I use for single objects and for list of object (Read operation and GetAll operation)

        protected virtual void CacheAddData(DomainObject domainObject)
        {
        if (domainObject != null)
        {
        CacheDictionary[this.GetType().FullName].Add(this.GetType().FullName + "_" + domainObject.GetId(), domainObject);

            List<DomainObject> cachedObj = CacheGetAllData();
            if (cachedObj != null && cachedObj.Count > 0)
            {
                int idx = -1;
                try
                {
                    idx = cachedObj.FindIndex(a => a.GetId() == domainObject.GetId());
                    cachedObj.RemoveAll(a => a.GetId() == domainObject.GetId());
                }
                catch (NullReferenceException)
                {
                    BusinessFacade.ApplicationLogger.Write("INFO: Cache: Linq exception", Category.General, Priority.Normal, 1, System.Diagnostics.TraceEventType.Information);
                }
        
                if (idx >= 0)
                    cachedObj.Insert(idx, domainObject);
                else
                    cachedObj.Add(domainObject);
                CacheAddAllData(cachedObj);
            }
        }
        

        }

        So what the above do is to add an item in cache and if exist a list of that objects retrive it and add/insert in the right position the item. Now the bug: Everything is running fine. 100+ people use the system without a glitch. BUT sometime, near middle of the day, one or two people report a nullreference exception, especially in this code:

        List<Utente> decoratori = GetAll().Cast<Utente>().ToList().Where<Utente>(u => u.Ruolo.IsDecoratore()).ToList();

        the where iterator crash stating that object is null (I do checks before the only null objects can be the "Ruolo") Now this is the issue: the same user with everyting unchanged became without an attribute (non deterministic). Recycling the IIS memory fix the issue (so is not a reproducible issue).

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        I had a problem like that but with xml reading and writing. As more bots crawled the site, at a very fast pace, my program would crash, because the file was still open. I had to really fine tune the program about 10 times, with more verification, and to open, read and close as fast as possible, then work in memory only, when done open write and close, then dump the memory and cleanup. I know it's not the same problem, but in principal, the code had to be as efficient as possible.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups