Deletes Are Driving Me Crazy

Skylos skylos at gmail.com
Wed Jan 11 19:01:17 UTC 2006


I dunno the architecture of your application...

But were I doing this in a straightforward way... in a perlish sort of way...

$mc->delete($key,$val);
unless ($mc->add($key,$val2)) {
    $mc->replace($key, $val2);
}

But, if it was something on the order of

Destroy objectinstanceA
Create objectinstanceB

where the destructor of A deletes, and the creator of B adds, it might
be alot harder to do that.

In that case, I could see a serious problem regarding this behavior.

Then I start to be hacky.

I'll do something like

sub DESTROY {
    $mc->add($key . "-okaytoreplace", 1) unless ($mc->incr($key .
"-okaytoreplace"));
    $mc->delete($key);
}

sub new {
    unless ($mc->add($key, $value)) {
        unless ($mc->decr($key . "-okaytoreplace")) {
            $mc->replace($key, $value);
        } else {
            error("add failed no overwrite");
        }
    }
}

But... maybe that not work for you.  I dunno.

Just a thought,

Skylos

PS - pardon my perlisms.


More information about the memcached mailing list