简体   繁体   中英

Memcached does not save generated data

I got the following code which should save the query data to the Memcached if called and store it there for 600ms. But every time i load the page the $response is empty and the var_dump says MISS. Any ideas what i'm doing wrong? The Memcached Server is on port 11211 as ps aux | grep memcached ps aux | grep memcached tells me.

$memcache = new Memcached();
$memcache->addServer("127.0.0.1", 11211);
$response = $memcache->get("test");
var_dump($response);
if ($response) {
    var_dump('HIT');
    $result = $response;
} else {
   var_dump('MISS');
   $sql = 'SELECT * FROM test WHERE bla BETWEEN "'.esc_sql($start).'" AND "'.esc_sql($end).'" ORDER BY datumbekanntgabe ASC';

   $result = $this->mydb->get_results($sql);
   $memcache->set("test", $result, 0, 600);
}
return $result;

It looks as though it was using 0 as the timeout, in the call...

$memcache->set("test", $result, 0, 600);

In memcache , the third parameter - 0 is a flag used for compression, whilst the fourth is the timeout, in memcached though this flag isn't present, so the call should be

$memcache->set("test", $result, 600);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM