# Memcached Configuration in CakePHP 3x

**URL:** <https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425>\
**Category:** Need Help\
**Created:** [May 29, 2016, 6:51pm UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425 "2016-05-29T18:51:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vexedmonkey](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/vexedmonkey/32/230_2.png) [@vexedmonkey](https://discourse.cakephp.org/u/vexedmonkey)\
**Post date:** [May 29, 2016, 6:51pm UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/1 "2016-05-29T18:51:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alysson\_azevedo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/alysson_azevedo/32/194_2.png) [@alysson\_azevedo](https://discourse.cakephp.org/u/alysson_azevedo)\
**Post date:** [May 29, 2016, 6:58pm UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/2 "2016-05-29T18:58:19Z")

</div>

The config i use is:

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

```

Hope it helps you.

---

<div class="post-metadata">

**Author:** ![rpuerto](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rpuerto](https://discourse.cakephp.org/u/rpuerto)\
**Post date:** [November 21, 2018, 3:02am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/3 "2018-11-21T03:02:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rpuerto](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rpuerto](https://discourse.cakephp.org/u/rpuerto)\
**Post date:** [January 10, 2019, 8:15am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/4 "2019-01-10T08:15:41Z")

</div>

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),
    ],
],
```

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [January 10, 2019, 8:17am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/5 "2019-01-10T08:17:11Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [January 10, 2019, 8:24am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/6 "2019-01-10T08:24:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpuerto](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rpuerto](https://discourse.cakephp.org/u/rpuerto)\
**Post date:** [January 10, 2019, 8:25am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/7 "2019-01-10T08:25:09Z")

</div>

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.  
 ![memcache](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/2X/e/ef2a62e7e47c90542ff8d51e47bc13cde519ff07.png)

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [January 10, 2019, 8:28am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/8 "2019-01-10T08:28:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpuerto](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rpuerto](https://discourse.cakephp.org/u/rpuerto)\
**Post date:** [January 10, 2019, 8:42am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/9 "2019-01-10T08:42:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpuerto](https://avatars.discourse-cdn.com/v4/letter/r/e19b73/32.png) [@rpuerto](https://discourse.cakephp.org/u/rpuerto)\
**Post date:** [January 10, 2019, 8:57am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/10 "2019-01-10T08:57:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [January 10, 2019, 9:00am UTC](https://discourse.cakephp.org/t/memcached-configuration-in-cakephp-3x/425/11 "2019-01-10T09:00:54Z")

</div>

Glad I could help 🙂

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