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

2022/1/12 20:03:53

本文主要是介绍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
返回: 2,get 访问:
http://127.0.0.1:8000/yac/getcache
返回: 3,del 访问:
http://127.0.0.1:8000/yac/delcache
返回:   4,flush 访问:
http://127.0.0.1:8000/yac/flushcache
返回:

三,查看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: 使用yac做缓存(php 8.1.1 / thinkphp v6.0.10LTS )的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程