user3553297
user3553297

Reputation: 5

php memcache not working with mvc

I have two different Controller. i am working with Zend Framework MVC

Controller 1. Set data

Controller 2. Get Data and display

So i did it simply:

Controller 1.

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$data = array('id'=>1,'Name'=>'Jonson');
$key = "PersonalDetail";
$memcache->set($key,$data,MEMCACHE_COMPRESSED,1200);

Controller 2.

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");
$key = "PersonalDetail";
$Data = $memcache->get($key);

var_dump($Data); //getting nothing.

I checked for the key if it is set or not. and i get this it is set in Controller 1 . but when i run Controller 2 code and then check key.. i didn't exists there anymore.

Is this happening because i am connecting memcache again to get data? or is there anyother thing happening?

Please help.

Upvotes: 0

Views: 116

Answers (1)

Prisoner
Prisoner

Reputation: 27618

Memcached keys cannot contain spaces, set the key to personal_detail. See the specs:

Data stored by memcached is identified with the help of a key. A key is a text string which should uniquely identify the data for clients that are interested in storing and retrieving it. Currently the length limit of a key is set at 250 characters (of course, normally clients wouldn't need to use such long keys); the key must not include control characters or whitespace.

Upvotes: 2

Related Questions