0

Is there any configuration hint for enabling memcache in Craft 3? I'm on 3-beta-24

I added

'cacheMethod' => 'memcache',

to config/general.php, but this did neither cause any hits on memcache nor any error.

The Craft 2 (sic!) docs say you also need config/memcache.php, which I created

  1. returning an empty array
  2. returning an array containing the properties I found in *app/vendor/craftcms/cms/src/config/MemCacheConfig.php:
  3. returning a 2 dimensional array with the the first array containing the properties from 2. above

Nothing worked, but 2. & 3. throw unknown property exceptions.

This is my memcache.php (according to variant 3. above):

return [
    [        // A memcached server hostname or IP address.
        'host' => 'localhost',
        // Whether or not to use a persistent connection.
        'persistent' => true,
        // The memcached server port.
        'port' => 11211,
        // How often a failed server will be retried (in seconds).
        'retryInterval' => 15,
        // If the server should be flagged as online upon a failure.
        'status' => true,
        // The value in seconds which will be used for connecting to the server.
        'timeout' => 15,
        // Probability of using this server among all servers.
        'weight' => 1,
    ]
];

This is the exception:

Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: craft\config\MemCacheConfig::0
 in .../app/vendor/yiisoft/yii2/base/Object.php at line 161

looks like the config can't handle multiple memcache servers as array.

Here's the stacktrace: https://pastebin.ca/3855627

8
  • 'cacheMethod' => 'memcache' is correct and #3 is correct. What was the error you were getting in that situation? And is memcache installed locally and are you able to connect to it with those settings from the command line?
    – Brad Bell
    Aug 15 '17 at 20:26
  • With #3 I get: Unknown Property – yii\base\UnknownPropertyException Setting unknown property: craft\config\MemCacheConfig::0 I have memcache enabled in MAMP, though not verified it works. But I would expect some "can not connect" error or successful hits in the memcache log. Neither happens. Aug 15 '17 at 20:46
  • Can you edit the original question and share the error with the full stack trace leading up to it? As well as the full contents of your craft/config/memcache.php file.
    – Brad Bell
    Aug 15 '17 at 20:54
  • did it. do you really want the full stack trace? Aug 15 '17 at 21:06
  • Yeah, full stack trace, please. Trying to determine if this is a Craft 3 bug or not.
    – Brad Bell
    Aug 15 '17 at 21:16
2

If you look at the MemCacheConfig.php file, you'll see that it's expecting a single property, "servers", which contains an array of associative arrays with properties. So, try this as your memcache config:

<?php
return [
    'servers' => 
[
  [        // A memcached server hostname or IP address.
             'host' => 'localhost',
             // Whether or not to use a persistent connection.
             'persistent' => true,
             // The memcached server port.
             'port' => 11211,
             // How often a failed server will be retried (in seconds).
             'retryInterval' => 15,
             // If the server should be flagged as online upon a failure.
             'status' => true,
             // The value in seconds which will be used for connecting to the server.
             'timeout' => 15,
             // Probability of using this server among all servers.
             'weight' => 1,
    ]
  ]
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.