zoukankan      html  css  js  c++  java
  • 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 
  • 相关阅读:
    web前端的发展态势
    AngularJs 简单入门
    css代码优化篇
    git提交报错:Please make sure you have the correct access rights and the repository exists.
    Activiti工作流框架学习
    遍历map集合的4种方法
    js设置日期、月份增加减少
    Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
    webservice_rest接口_学习笔记
    相互匹配两个list集合+动态匹配${}参数
  • 原文地址:https://www.cnblogs.com/architectforest/p/15794716.html
Copyright © 2011-2022 走看看