thinkphp6: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS )

一,访问yac的php代码:

1,创建controller
liuhongdi@lhdpc:/data/php/admapi$ php think make:controller Yac
Controller:app\controller\Yac created successfully.
2,controller/Yac.php
<?php
declare (strict_types = 1);
 
namespace app\controller;
 
use think\Request;
 
class Yac
{
    /**
     * set Cache
     *
     * @return \think\Response
     */
    public function setCache()
    {
        $yac = new \Yac("goods_");
        $yac->set('a', 'value a');
        $yac->set('b', [1,2,3,4]);
        echo "set end<br/>";
    }
 
    /**
     * get cache
     *
     * @return \think\Response
     */
    public function getCache()
    {
        $yac = new \Yac("goods_");
        echo $yac->get('a')."<br/>"; // value a
        echo $yac->a."<br/>"; // value a
        print_r($yac->get('b'));
        echo "<br/><br/>";
        $all = $yac->dump(1000);
        var_dump($all);
        echo "<br/><br/>";
        $info = $yac->info();
        var_dump($info);
    }
 
    /**
     * del Cache
     *
     * @return \think\Response
     */
    public function delCache()
    {
        $yac = new \Yac("goods_");
        echo "before delete:<br/>";
        print_r($yac->get('b'));
        echo "<br/>";
        $yac->delete('b');
        echo "after delete:<br/>";
        print_r($yac->get('b'));
    }
 
    /**
     * flush Cache
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function flushCache()
    {
        $yac = new \Yac("goods_");
        echo "before flush:<br/>";
        $all = $yac->dump(1000);
        var_dump($all);
        echo "<br/>";
        $yac->flush();
        echo "after flush:<br/>";
        $all = $yac->dump(1000);
        var_dump($all);
    }
}

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,测试yac效果

1,set 访问:
http://127.0.0.1:8000/yac/setcache
返回: thinkphp6: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS ) 2,get 访问:
http://127.0.0.1:8000/yac/getcache
返回: thinkphp6: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS ) 3,del 访问:
http://127.0.0.1:8000/yac/delcache
返回: thinkphp6: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS )   4,flush 访问:
http://127.0.0.1:8000/yac/flushcache
返回: thinkphp6: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS )

三,查看php和thinkphp的版本: 

php:
liuhongdi@lhdpc:/data/php/admapi$ php --version
PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies 
thinkphp:
liuhongdi@lhdpc:/var/www/html$ cd /data/php/admapi/
liuhongdi@lhdpc:/data/php/admapi$ php think version
v6.0.10LTS 

 

上一篇:thinkphp6: 在extend目录下开发扩展类(php 8.1.1 / thinkphp v6.0.10LTS )


下一篇:docker19.03限制容器使用的cpu资源