之前不明白缓存有什么用处,后来看了一些案例大概有点了解,记录一下。
1、thinkphp5没有静态缓存
2、对于一些更新不是太频繁的数据,我们可以使用缓存机制对查询到的数据进行缓存,减缓数据库压力
3、下面讲的例子缓存类型都是file,{memcache、wincache、sqlite、redis和xcache}这几种目前还不了解
4、应用配置文件中默认是有缓存配置的

if(!Cache::get('dat')) {            //判断缓存是否存在

      $data = db('user')->select();//查询数据库数据
Cache::set('dat',$data,30); //设置缓存
} Cache::get('dat'); //读取缓存

//设置查询缓存,查询到的数据也会生成缓存文件在60秒内有效


$data=db('user')->cache(true,60,'file')->select();

 

具体参考thinkphp5参考手册:https://www.kancloud.cn/manual/thinkphp5/118131

thinkphp5缓存使用的更多相关文章

  1. THINKPHP5获取设置缓存的例子

    在THINKPHP5中 缓存的配置放在了config.php文件中 代码如下 如何设置缓存? 可以使用静态方法 Cache::set('key',$value,3600);//存储缓存 Cache:: ...

  2. thinkphp5简单使用redis缓存

    <?php namespace app\index\controller; use think\Controller; use think\Cache\Driver\Redis; class I ...

  3. ThinkPHP5配置redis缓存

    thinkphp采用cache类提供缓存功能支持,采用驱动方式,在使用缓存之前需要进行初始化操作.支持的缓存类型包括file.memcache.wincache.sqlite.redis和xcache ...

  4. ThinkPHP5.0源码学习之缓存Cache(二)

    一.使用Cache类 TP5.0框架默认使用的是File文件缓存驱动,可以修改全局配置文件convention.php中的type,将其改为Redis,这样使用的就是Redis缓存驱动了.

  5. ThinkPHP5.0源码学习之缓存Cache(一)

    一.文件 1.缓存配置文件:thinkphp\convention.php 2.缓存文件:thinkphp\library\think\Cache.php 3.驱动目录:thinkphp\librar ...

  6. thinkphp5的Redis缓存配置

    thinkphp采用cache类提供缓存功能支持,采用驱动方式,在使用缓存之前需要进行初始化操作.支持的缓存类型包括file.memcache.wincache.sqlite.redis和xcache ...

  7. thinkphp5.0 页面缓存

    在application\config.php里加 //以下为静态缓存配置 'app_debug' => false,//false为开启静态缓存模式 'html_cache_on' => ...

  8. thinkphp5.0 cache数据缓存机制

    use think\cache; public function index(){ //Cache::get('name')获取缓存,如果name值不存在则返回false: if (Cache::ge ...

  9. thinkphp5一键清除缓存

    入口文件定义缓存文件路径常量 define('DS', DIRECTORY_SEPARATOR); defined('APP_PATH') or define('APP_PATH', dirname( ...

随机推荐

  1. codeforces 628C C. Bear and String Distance

    C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. java将白色背景图片转换成透明图片

    package evecom.image; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.Buffe ...

  3. ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)

    Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...

  4. bzoj 4199: [Noi2015]品酒大会 后缀树

    题目大意: 给定一个长为n的字符串,每个下标有一个权\(w_i\),定义下标\(i,j\)是r相似的仅当\(r \leq LCP(suf(i),suf(j))\)且这个相似的权为\(w_i,w_j\) ...

  5. 如何在virtualenv环境中安装指定的python版本

    指定python版本:virtualenv   -p python执行文件路径     自定义虚拟环境名称.如果文件路径有空格,用引号. 如果不指定python版本,则默认使用环境变量中的python ...

  6. Swift中数组和字典都是值类型

    在 Swift 中,所有的基本类型:整数(Integer).浮点数(floating-point).布尔值(Boolean).字符串(string).数组(array)和字典(dictionary), ...

  7. Tomcat配置MySql连接池问题

    配置过程如下: 1.修改Tomcat—>conf目录下的context.xml文件 <Context path="/DBTest" docBase="DBTe ...

  8. sessionStorage,localStorage,cookies

    1 HTML5的Storage主要分为两种:localStorage与sessionStorage,这两者主要在生命周期上有较明显的差别,localStorage的生命周期较长,原则上要等到透过Jav ...

  9. NSDictionary和NSArray

    // 字典里套数组 NSArray *array1 = @[@"huahau" , @"hehe"]; NSArray *array2 = @[@"x ...

  10. 左连接,右连接,内连接,Union

    数据库的三种常用连接解析: 官方解释: 1.left [outer] join(左外联接) 返回 包括左表中的所有记录和右表中联结字段相等的记录 2.right [outer] join(右外联接) ...