Problem with Isolated Storage in Cache application block

Topics: Caching Application Block
Jan 30, 2009 at 2:19 PM
Hi All,

    I am using Enterprise library block 4.0 of May 2008. I have implemented cache application block in my windows service. I have developed multi-threaded service which reads the messages from MSMQ. It get stored on FileSystem using cache application block. I have created Cache manager with Isolated Storage for it. It mentioned on the msdn that cache application block is thread safe... My 1st question is.

1) I am using cache application block with Isolated Storage. Is this Cache manager is thread safe?

I am storing lot of messages using above cache manager with multi-threaded approach. These threads updates the stored values of cached data using cache manager. I have tested it for more than 500 messages. It works well but some time I got the error like "Unable to delete, directory not empty or does not exist". I have used locks while doing add/remove operations on  cache manager.

I want to know the reason of this kind of un-predictable error if cache application block is thread safe. This windows service is still in development but I don't want to take risk for production release. Otherwise all the blocks are simply great...

Please spend your valuable time to solve my problem.. I will be thankful for you.



Feb 2, 2009 at 9:52 AM
I believe the statement applies to the cache manager regardless of what storage is used.   Do all your errors happen during method calls from the cache manager?  After using locks, are you still encountering the same errors?, regardless if it's inconsistent or consistent when you didn't apply locks.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Feb 2, 2009 at 11:59 AM
Thanks for the reply.... Yes I got the exceptions sometime(inconsistently) during cache manager method call. I have applied lock on cache manager object. I got the error on Add/Remove method of cache manager. I am trying to process 500 messages & now this errors get occur for 2-3 messages. These messages are not common everytime. I will provide more info if require.
Feb 2, 2009 at 1:30 PM
Edited Feb 2, 2009 at 1:31 PM
Here is the stack strace of the exception.

   at System.IO.IsolatedStorage.IsolatedStorageFile.DeleteDirectory(String dir)
   at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.RemoveItem(String itemLocation)
   at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.Remove(Int32 storageKey)
   at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.IsolatedStorageBackingStore.RemoveOldItem(Int32 storageKey)
   at Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.BaseBackingStore.Add(CacheItem newCacheItem)
   at Microsoft.Practices.EnterpriseLibrary.Caching.Cache.Add(String key, Object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, ICacheItemExpiration[] expirations)
   at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager.Add(String key, Object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, ICacheItemExpiration[] expirations)
   at EdgarOnline.CommonLibrary.CacheManager.AddPendingJob(String jobKey) in D:\FileQueueService\CommonLibrary\CacheManager.cs:line 482
Feb 4, 2009 at 1:43 AM
Just to clarify again, it's not clear to me based on your previous reply if you still got those errors after applying lock on the cache manager.  I remember creating a component (no entlib component involved) once which do some code generations stuff which involves creating, moving, deleting directory, adding, updating and deleting files.  I also intermittently encounter the same errors and I never got a solution or even a clue why it is happening.  I even note the steps how I encounter those errors but when trying to repro them, nothing, it's really inconsistent and frustrating.  

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Feb 4, 2009 at 8:44 AM
    Yes, I have applied lock on cache manager and I am still getting error same sometime. As per your experience, I will feel very inconsistent while sending my application to the client.. :-) But you said, you haven't used EntLib, Do you have any idea about EntLib hotfix to resolve this kind of problem? Will you please try to reproduce same problem using EntLib?
    I am agree that error is inconsistent and it will frustrate me toooo..... Thanks for the information uptill now... I have 1 small question about code in EntLib .DeleteDirectory method. Why lock/monitor not applied to the specific folder of isolated storage while doing add/delete/update operations?

Waiting for solution...


Feb 4, 2009 at 10:26 AM
Edited Feb 4, 2009 at 10:50 AM
I had used entlib before and currently using it.  What I meant is that the component I was referring to doesn't have anything to do with entlib.  My point is, maybe the Directory.Delete is causing the problem. (maybe).  I don't know any hotfix for this as I haven't seen any post having the same issue as yours before.  As per your question regarding not applying locks, I can't answer that as it's a decision made by the developers.  Anyway, I'll see what I can find out about your problem.  

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.