Memcached Configuration in CakePHP 3x


#1

I am a previous CakePHP 2 user and am starting a new application using CakePHP3, I have searched but am finding very little examples and/or detailed instructions on the configuration of Memcached for my application.

In CakePHP 2 I simply created a Cache configuration like:

Cache::config(‘5m’, array(
‘engine’ => ‘Memcached’,
‘duration’ => 3600,
‘servers’ => array(‘127.0.0.1:11211’)));

I am unable to find an example that is equivalent to this for CakePHP 3. I have tried using:

‘Cache’ => [
‘5m’ => [
‘className’ => ‘Memcached’,
‘duration’ => ‘+5 minutes’,
‘servers’ => ‘127.0.0.1:11211’
],

However I receive “Cache engine Cake\Cache\Engine\MemcachedEngine is not properly configured.” error which tells me almost nothing on what needs to be adjusted. I am sure this is a simple configuration / syntax issue on my part, however, I am unable to find a full working example or description on how to get memcached usable in CakePHP 3.

  • I know Memcached is installed correctly and running as all of my CakePHP 2 applications are using it just fine.

  • I’d prefer to not use the DSN format.

Any help is appreciated.


#2

The config i use is:

'flags' => [
    'className' => 'Cake\Cache\Engine\MemcachedEngine',
    'prefix' => 'flags_data_',
    'path' => CACHE . 'flags/',
    'duration' => '+10 seconds'
]

Hope it helps you.


#3

I have the same issue with cakephp 3, error in “ Cache engine Cake\Cache\Engine\MemcachedEngine is not properly configured. ”.

Cache::config(‘long’, [
‘className’ => ‘Cake\Cache\Engine\MemcachedEngine’,
‘prefix’ => ‘flags_data_’,
‘path’ => CACHE . ‘flags/’,
‘duration’ => ‘+10 seconds’
]);

This settings not working for me. any help?


#4

I have update my code to the lastest cakephp 3 in my app.php but still not working. I installed memcache and memcached in my centos server. Cakephp 2 its working fine but in cakephp 3 its not working throws error Cache engine Cake\Cache\Engine\MemcachedEngine is not properly configured.

  'Cache' => [
   
   'default' => [
        'className' => 'Cake\Cache\Engine\MemcachedEngine',
    ],

    /**
     * Configure the cache used for general framework caching.
     * Translation cache files are stored with this configuration.
     * Duration will be set to '+2 minutes' in bootstrap.php when debug = true
     * If you set 'className' => 'Null' core cache will be disabled.
     */
    '_cake_core_' => [
        'className' => 'File',
        'prefix' => 'myapp_cake_core_',
        'path' => CACHE . 'persistent/',
        'serialize' => true,
        'duration' => '+1 years',
        'url' => env('CACHE_CAKECORE_URL', null),
    ],

    /**
     * Configure the cache for model and datasource caches. This cache
     * configuration is used to store schema descriptions, and table listings
     * in connections.
     * Duration will be set to '+2 minutes' in bootstrap.php when debug = true
     */
    '_cake_model_' => [
        'className' => 'File',
        'prefix' => 'myapp_cake_model_',
        'path' => CACHE . 'models/',
        'serialize' => true,
        'duration' => '+1 years',
        'url' => env('CACHE_CAKEMODEL_URL', null),
    ],
],

#5

@rpuerto

Please clarify what you mean by it’s not working. What error do you see, what else have you tried?

Do you have memcached installed and running, and what is the memcached instances settings (Specifically host and port)


#6

Just saw your edit.

So, the reasons that memcached will throw that error are:

  • The memcached php extension is not installed (Be careful here, Cake 2.x could use the old memcache extension, it’s possible you don’t have the correct one installed)
  • The memcached servers are not available

#7

I see this error Warning (512): Cache engine Cake\Cache\Engine\MemcachedEngine is not properly configured. in [/home/apidata/public_html/vendor/cakephp/cakephp/src/Cache/Cache.php, line 177]

Memcache is already installed in our server.


#8

Ah, there is your problem :slight_smile: CakePHP 3.x requires the new memcached extension, not the old memcache extension.


#9

I see If i installed the correct memcached what will happen to cakephp 2 is his caching still works?


#10

I installed both the memcached and memcache in php ini and its now working fine. The problem is now solved. thanks @dakota.


#11

Glad I could help :slight_smile:

You can/should also switch Cake 2.x to use memcached, it is faster than the old one.