Environment:
Operating system: Windows 7;
php:5.6.8
apche:2.4.12
1, first install PHP memcache expansion, installation method is as follows:
1.1 Download memcache Extension DLL:
Http://pecl.php.net/package/memcache/3.0.8/windows
1.2 Copy Php_memcache.dll to Php/ext directory
1.3 Adjust the php.ini, add the configuration at the bottom:
Extension=php_memcache.dll
2. Add YII2 configuration:
Modify in the project config/web.php file
Components>=cache Configuration modifications are configured as follows:
The calling method is as follows:
<?PHP/** * Created by Phpstorm. * USER:WANGK * DATE:2015/4/27 * time:10:34*/namespace App\common; UseYii; classCachemanage {//Cache prefix Constcache_prefix= ' Myrhythmk_ '; Private Static functionGetKey ($key) { returnSelf::cache_prefix.$key; } Public Static functionGet$key) { returnYII::$app->cache->get (Self::getkey ($key)); } Public Static functionSet$key,$value,$duration= 0,$dependency=NULL) { returnYII::$app->cache->set (Self::getkey ($key),$value,$duration,$dependency); } Public Static functionDelete$key) { returnYII::$app->cache->delete (Self::getkey ($key)); }}
Under Windows YII2 configuration Memcache