I am currently using Dustin's Java library (memcached-2.0-pre7). I havn't
seen any CAS function in that. So safely assuming that I need to continue to
use java for my project ( :) ) , what are the alternatives that I have ?

So from my understanding of CAS, I can pass a unique code, that I get from
"get" operation,  to the "set" operation. And in case it fails, I would need
to fetch the latest value and update the cache entry again ( this would need
to some kind of loop to make sure that I don't miss pushing any updates to
cache).

-Rakesh

On Fri, Feb 22, 2008 at 1:48 AM, Reinis Rozitis <[EMAIL PROTECTED]> wrote:

> Hearing term 'lock' and 'locking' near memcache just doesnt sound the
> correct way to do things... Its ment to be a nonblocking cache ..
>
> I am not sure if there is implementation in java client  (using only php
> pecl extension) but the thing you prolly want to look at is CAS (compare
> and
> swap) http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
>
> rr
>
> ----- Original Message -----
> From: Rakesh Rajan
> To: [email protected]
> Sent: Thursday, February 21, 2008 8:23 PM
> Subject: Collection + Concurrent Update
>
>
> Hi,
>
> I am using memcached to store a lot of collections. An example would be,
> for
> a given item, a collection of integers representing various attributes.
> Now,
> since there can be concurrent update to the collection ( addition /
> deletion
> / updation ), there are times when the cached data gets stale/dirty.
> Example
> Current Cache [ 1,2]
>
>   Thread 1 ( Added 3 ) : [1,2,3]
>   Thread 2 ( Added 4 ) : [1,2,4]
>   Thread 3 ( Removed 2 ) : [1]
>
> Now when all 3 threads tries to update the cache, cache becomes dirty. One
> way to solve this is, for every set operation, I would need to get the
> current cached collection and then perform operation (
> addition/deletion/updation) on it before setting it back ( with the write
> operation acquiring a lock first ).
>
> For a typical write, I do
>    -> Take a lock ( with ~1-2 secs timeout)
>    -> Fetch the current cache value ( if any)
>       -> Perform the operation between the cached data and the newer data
> ( addition/deletion/updation)
>    -> Update the cache with the newer collection
>    -> Release the lock ( this is purely a safety mechanism : in the
> finally
> block of the java code )
>
> So every write operation, I need to make 4 memcached calls which I believe
> is not a good solution ( since it is in the same thread). One possible
> solution that I was thinking was making the cache update async process.
> Would love to hear how this case is generally solved / opinions ?  ( In my
> case collections are either Set / List )
>
> -Rakesh
>
>

Reply via email to