MemCache supports both memcache and
memcached. By setting [[useMemcached]] to be true or false,
one can let MemCache to use either memcached or memcache, respectively.
MemCache can be configured with a list of memcache servers by settings its [[servers]] property.
By default, MemCache assumes there is a memcache server running on localhost at port 11211.
See Cache for common cache operations that MemCache supports.
Note, there is no security measure to protected data in memcache.
All data in memcache can be accessed by any process running in the system.
To use MemCache as the cache application component, configure the application as follows,
php
[
'components' => [
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => 'server1',
'port' => 11211,
'weight' => 60,
],
[
'host' => 'server2',
'port' => 11211,
'weight' => 40,
],
],
],
],
]
In the above, two memcache servers are used: server1 and server2. You can configure more properties of
each server, such as persistent, weight, timeout. Please see MemCacheServer for available options.
For more details and usage information on Cache, see the guide article on caching.