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 
  • 相关阅读:
    Luogu P2480 [SDOI2010]古代猪文 卢卡斯+组合+CRT
    luogu 3806 【模板】点分治
    poj 1741 Tree(树的点分治)
    置换群(本蒟蒻瞎BB的)(未完)
    uva 1153 顾客是上帝(贪心)
    关于区间的贪心问题
    uva 1615 高速公路(贪心,区间问题)
    uva 1614奇怪的股市(归纳法证明,贪心)
    uva11491 奖品的价值(贪心)
    uva12545 比特变换器(贪心)
  • 原文地址:https://www.cnblogs.com/architectforest/p/15794716.html
Copyright © 2011-2022 走看看