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
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返回:
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 Technologiesthinkphp:
liuhongdi@lhdpc:/var/www/html$ cd /data/php/admapi/ liuhongdi@lhdpc:/data/php/admapi$ php think version v6.0.10LTS