PHP code example of phpmicroservice / cache_manage
1. Go to this page and download the library: Download phpmicroservice/cache_manage library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpmicroservice / cache_manage example snippets
# 定义缓存驱动
# 详见 src/Driver/Symfony.php
# 定义缓存管理器
/**
* Description of Time3
* 三秒缓存
* @author dongasai
*/
class Time3 extends \CacheManage\AbstractCache
{
protected $ttl = 3;
protected $dirver = Symfony::class;
public function handle()
{
return time();
}
}
# 使用缓存管理器,这个缓存管理器是无参数的
$time3 = new Time3();
$timeCache = $time3->get();
echo $timeCache;
/**
* Description of Team
* 组 缓存管理
* @method \test\Table\Team get()
* @author dongasai
*/
class Team extends \CacheManage\AbstractCache
{
protected $dirver = Symfony::class;
public function handle()
{
$id = $this->param_arr[0];
$team = new \test\Table\Team(['id'=>$id]);
$this->selfTags[] = "team_$id";
return $team;
}
}
/**
* 用户 缓存管理
* @method \test\Table\User get()
*/
class User extends AbstractCache
{
protected $dirver = Symfony::class;
public function selfTags(): array
{
return $this->selfTags;
}
public function handle()
{
$id = $this->param_arr[0];
$this->selfTags[] = "user_$id";
$user = new \test\Table\User(['id' => $id]);
$teamId = $user->getTeamId();
$this->relatedTags[] = "team_$teamId";
return $user;
}
}
$User = new User();
$UserCache = $User->get([1]);
//实例化传入参数
(new User([1]))->get();
// 获取时传入参数,会覆盖原本的参数
(new User())->get([1]);
// 实例化传入过期时间
(new User([1],100))->get();
// 获取数据时传入过期时间,,会覆盖原本的过期时间
(new User())->get([1],100);
public function handle()
{
$offset = $this->param_arr[0];
return time() + $offset;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.