码迷,mamicode.com
首页 > Windows程序 > 详细

windows 下 YII2 配置 memcache

时间:2015-04-27 15:04:29      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

  环境:

      操作系统 :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 app\common;

  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));
     }

}

 

 



 

windows 下 YII2 配置 memcache

标签:

原文地址:http://www.cnblogs.com/rhythmK/p/4460083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!