1

I have an issue trying to use cacheengine with Xcache:

When I use File Or Memcache, the cache engine works fine, it save datas and read them successfully from cache.

When I try to use Xcache, it saves datas (Cache::Write() returns 1) but Cache::read() returns nothing.

In my bootstrap.php:

Cache::config('12h', array(
                          'engine'   => 'Xcache',
                          'duration' => '+12 hours',
//                          'path'     => CACHE,
//                          'prefix'   => 'cake_12h_'
                     ));

In the core.php:

Cache::config('Xcache', array(
                             'engine' => 'Xcache', //[required]
                             'duration'    => 3600, //[optional]
                             'probability' => 100, //[optional]
                        ));

The main function where I use cache:

public function pronostics() {

        $this->set('title_for_layout', 'Pronostics');

        if ($this->_isUserLogged()) {

            $pronostics = Cache::read('pronostics', '12h');

            if (!$pronostics || isset($this->request->query['force'])) {
                $loginUrl = self::SITE_API_URL . '/api/getPronostics?auth_key=123&user_id=' . self::SITE_ID;

                list($httpCode, $res) = $this->_curlIt($loginUrl, false, false);

                if ($httpCode === 200) {
                    $res = json_decode($res);
                    if (is_object($res) && $res->status == 'success') {

                        $pronostics = $res->pronostics;

                        $res = Cache::write('pronostics', $pronostics, '12h');
                        $this->log($res, 'curl');
                    } else {
                        $this->redirect(array('controller' => 'interactions', 'action' => 'pronostics'));
                    }
                }
            }

            $this->set('pronostics', $pronostics);

        } else {
            $this->Session->setFlash('Pour accéder aux pronostics, vous devez être identifié.', 'default', array(), 'error');
            $this->redirect(array('controller' => 'interactions', 'action' => 'index', '?' => array('login_error' => 1)));
        }
    }

Do you know why xcache does not works in my case ? Thanks.

zeflex
  • 1,487
  • 1
  • 14
  • 29
  • Is Xcache enabled and working on the server? In SSH you can run `php -v` and it should say "with Xcache vx.x.x". Or use `phpinfo();` – Corie Slate Oct 16 '14 at 12:00
  • root@3WMEDIA01 [~]# php -v PHP 5.4.33 (cli) (built: Oct 15 2014 20:42:11) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with XCache v3.1.0, Copyright (c) 2005-2013, by mOo with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo root@3WMEDIA01 [~]# – zeflex Oct 16 '14 at 19:23
  • So yes Xcache is running but it seems maybe due to a bad config with CakePhp or I dunno :( – zeflex Oct 16 '14 at 19:24
  • Do your cached values show up in xcache-admin? – andy Oct 16 '14 at 20:17
  • I don't know to access to xcache admin... Is it a tool I should install in add than Xcache ? – zeflex Oct 16 '14 at 23:20
  • See [Step 5: Enabling XCache Admin Panel for PHP](http://www.tecmint.com/install-xcache-to-accelerate-and-optimize-php-performance/) – Corie Slate Oct 17 '14 at 05:01
  • @CorieSlate xcache is installed but I am not able to install xcache. I am on a vps with WHM/Cpanel/easyapache and I found no way for now to install the xcache admin – zeflex Oct 18 '14 at 16:40
  • What happens if you just `Cache::write()` and directly after `read()` a value? – andy Oct 19 '14 at 18:06
  • @andy this works but if I try to read the same value after refreshing page without the write before, the value returns false – zeflex Oct 19 '14 at 19:31
  • More details: xache in php.ini > http://pastebin.com/aLPkzZYp Simple function : http://pastebin.com/ywgA0Vnj > this works but if I try to read the same value after refreshing page without the write before, the value returns false – zeflex Oct 20 '14 at 03:33
  • You could try using xcache directly, see [API](http://xcache.lighttpd.net/wiki/XcacheApi), to check if that works. Your simple example uses another config `1h` instead of `12h`, is that intended? – andy Oct 20 '14 at 07:31

0 Answers0