ѡ̳

标题: thinkphp公共函数之S函数缓存函数 [打印本页]

作者: admin    时间: 2017-11-12 19:06
标题: thinkphp公共函数之S函数缓存函数
源码
  1. /**
  2. * 缓存管理
  3. * @param mixed $name 缓存名称,如果为数组表示进行缓存设置
  4. * @param mixed $value 缓存值
  5. * @param mixed $options 缓存参数
  6. * @return mixed
  7. */
  8. function S($name,$value='',$options=null) {
  9.     static $cache   =   '';
  10.     if(is_array($options) && empty($cache)){
  11.         // 缓存操作的同时初始化
  12.         $type       =   isset($options['type'])?$options['type']:'';
  13.         $cache      =   Think\Cache::getInstance($type,$options);
  14.     }elseif(is_array($name)) { // 缓存初始化
  15.         $type       =   isset($name['type'])?$name['type']:'';
  16.         $cache      =   Think\Cache::getInstance($type,$name);
  17.         return $cache;
  18.     }elseif(empty($cache)) { // 自动初始化
  19.         $cache      =   Think\Cache::getInstance();
  20.     }
  21.     if(''=== $value){ // 获取缓存
  22.         return $cache->get($name);
  23.     }elseif(is_null($value)) { // 删除缓存
  24.         return $cache->rm($name);
  25.     }else { // 缓存数据
  26.         if(is_array($options)) {
  27.             $expire     =   isset($options['expire'])?$options['expire']:NULL;
  28.         }else{
  29.             $expire     =   is_numeric($options)?$options:NULL;
  30.         }
  31.         return $cache->set($name, $value, $expire);
  32.     }
  33. }
复制代码







欢迎光临 ѡ̳ (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4