环境:
操作系统 :Windows 7;
php: 5.6.8
apche:2.4.12
1、首先安装PHP memcache 拓展,安装方法如下:
1.1下载 memcache 拓展DLL:
http://pecl.php.net/package/memcache/3.0.8/windows
1.2 拷贝php_memcache.dll 到 php/ext目录
1.3 调整php.ini,底部添加配置:
extension=php_memcache.dll
2、添加YII2配置:
在项目config/web.php 文件中修改
components>=cache 配置 修改配置如下:
调用方法 如下:
<?php /** * Created by PhpStorm. * User: wangk * Date: 2015/4/27 * Time: 10:34 */ namespace appcommon; use Yii; class CacheManage { // Cache前缀 const CACHE_PREFIX='myrhythmk_'; private static function getKey($key) { return self::CACHE_PREFIX.$key; } public static function get($key) { return Yii::$app->cache->get(self::getKey($key)); } public static function set($key, $value, $duration = 0, $dependency = null) { return Yii::$app->cache->set(self::getKey($key),$value,$duration,$dependency); } public static function delete($key) { return Yii::$app->cache->delete(self::getKey($key)); } }