bigdata4u / spymemcached

Automatically exported from code.google.com/p/spymemcached
0 stars 0 forks source link

This is a question not a issue #249

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using spymemcached client to implement my caching logic. Somehow I need to 
use CAS for concurrently modifying some content in the cache.

I saw the owner has already showed a very good example of how to use 
CASMutation from here: 
http://code.google.com/p/spymemcached/wiki/Examples#Using_CAS

But I have one question about this part of the code:

 // Not strictly necessary if you specify the storage as
 // LinkedList (our initial value isn't), but I like to keep
 // things functional anyway, so I'm going to copy this list
 // first.
 LinkedList<Item> ll = new LinkedList<Item>(current);

Even though I carefully read the comments, I still don't understand exactly 
what it is trying to do here. What if we just use "current" without copying to 
"ll"? What are the potential issues?

Can you guys answer this question for me? I really need to understand each line 
of code, before using it.

Thanks a lot 

Original issue reported on code.google.com by yaowen...@gmail.com on 25 Apr 2012 at 1:30

GoogleCodeExporter commented 8 years ago
Is it mainly because when we create the initial list, we use:
       List<Item> initialValue=Collections.singletonList(newItem);
This is a immutable list, so we need to copy it to a mutable list?

What if I just use the LinkedList initially, then after that whenever I need to 
add item, I just modify on the same object "current", will that cause 
concurrency issues?

Original comment by yaowen...@gmail.com on 25 Apr 2012 at 1:40

GoogleCodeExporter commented 8 years ago
Please do not use the issues board to ask questions. Questions should be asked 
on the google group for Spymemcached. They will also be answered much quicker.

>> This is a immutable list, so we need to copy it to a mutable list?

Yes we need to copy the list because it is immutable.

>> What if I just use the LinkedList initially, then after that whenever I need 
to add item, I just modify on the same object "current", will that cause 
concurrency issues?

If you just read from the list you don't need to copy it.

Original comment by mikewie...@gmail.com on 13 May 2012 at 5:15