Pregunta

I have a large amount of data in memcache, and currently i am troubling with How can i update value on memcache?

I have set value with multi-dimention array..

and now i have two cases here:

  1. I want to add new value in Memcache in same key
  2. I want to update some value of one particular array.

I know i can do that by get -> modify -> set

$data=$m->get('foo');

$data[]=array('id'=>134,'title'=>'My First Car','content'=>'I love my car');

$m->set('foo',$data,TRUE,0);

In this example..user can change its title, content etc. so i need to update these information in memcache.

But getting data on every change which is more than 1MB, that will not be a good idea.

and I also learn about append but it says it only works for string values. that means i can not append Array to with existing key.

Is there any way to set/update data on existing key without getting data?

Please help..

¿Fue útil?

Solución

Just call $m->get the first time to populate $data, and don't call it again if you're just making updates:-

if (!count($data))
    $data=$m->get('foo');

$data[]=array('id'=>134,'title'=>'My First Car','content'=>'I love my car');

$m->set('foo',$data,TRUE,0);

If you make $data global then you can reference it from other functions

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top