AppFabric Meultithreaded & cacheName

Jan 4, 2011 at 7:48 AM

Hi,

I have a multi-threaded application that need to write data in several cacheName.

The issue I encounter is that when the same thread is trying to write to another cache , the new cache is not updated since the namedCacheThreadTable is mapping ThreadID to CacheName.

For example I begin write in cacheName C1 , Region R1 so in my object I can see R1 in C1.

But after when the same thread is trying to write in cacheName C2 , Region R2 , the region R2 is written in cacheName C1 since the following lines are not adding the new cachename to the namedCacheThreadTable

if (!this._namedCacheThreadTable.ContainsKey(currentThreadId))
                        this._namedCacheThreadTable.Add(currentThreadId, cacheName);

 

Please help me with this issue and tell me if I am doing a correct use of this API.

 

Thank you.

Coordinator
Jan 4, 2011 at 3:46 PM

Hi,

Please follow the below mentioned convention to work with Named Cache in a Thread that needs to work with multiple Named Caches:

//In a Thread Execution
CacheBroker.SetNamedCache("C1");
//Perform operations on the Cache e.g.
CacheBroker.Get("Key1","Region1");
....
....
//The following statement set the default Cache as the Named Cache
//here onwards.
CacheBroker.SetDefaultCache();

....
....


//In a Same Thread Execution Later
CacheBroker.SetNamedCache("C2");
//Perform operations on the Cache e.g.
CacheBroker.Get("Key1","Region1");
//This time operations are performed on the NamedCache "C2"
....
....
//The following statement set the default Cache as the Named Cache
//here onwards.
CacheBroker.SetDefaultCache();


Hope it helps! 

Jan 4, 2011 at 3:58 PM
Thank you for the help.

נשלח מטלפון Nokia שלי
-----הודעה מקורית-----
מאת: RDas
נשלח: 04/01/2011 18:46:27
נושא: Re: AppFabric Meultithreaded & cacheName [Cache4DotNet:240371]

From: RDas

Hi,Please follow the below mentioned convention to work with Named Cache in a Thread that needs to work with multiple Named Caches://In a Thread ExecutionCacheBroker.SetNamedCache("C1");//Perform operations on the Cache e.g.CacheBroker.Get("Key1","Region1");........//The following statement set the default Cache as the Named Cache//here onwards.CacheBroker.SetDefaultCache();........//In a Same Thread Execution LaterCacheBroker.SetNamedCache("C2");//Perform operations on the Cache e.g.CacheBroker.Get("Key1","Region1");//This time operations are performed on the NamedCache "C2"........//The following statement set the default Cache as the Named Cache//here onwards.CacheBroker.SetDefaultCache();Hope it helps!