ѡ̳

 找回密码
 ע
搜索
查看: 203|回复: 0
打印 上一主题 下一主题

thinkphp公共函数之S函数缓存函数

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2017-11-12 19:06:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
源码
  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. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 05:55 , Processed in 0.077237 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0912s