Laravel Cache之File cache
Begin
2018年8月3日22:35:41
缓存配置文件:config/cache.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;
class CacheController extends Controller
{
public function options($type)
{
if($type == 'get'){
$this->cacheGet();
}
if($type == 'put'){
$this->cachePut();
}
if($type == 'add'){
$this->cacheAdd();
}
if($type == 'forever'){
$this->cacheForever();
}
if($type == 'has'){
$this->cacheHas();
}
if($type == 'pull'){
$this->cachePull();
}
if($type == 'forget'){
$this->cacheForget();
}
}
public function cacheGet()
{
//get() 获取缓存
//不存在则返回 null
$val = Cache::get('name');
dd($val);
}
public function cachePut()
{
//put
// key value time(Minute)
Cache::put('name','XXM',10);
}
public function cacheAdd()
{
//get
// key value time(Minute)
// 存在返回false 不存在则添加并返回true
$bool = Cache::add('name','XXM',10);
dd($bool);
}
public function cacheForever()
{
//forver
// key value 永久存在
Cache::forever('ip','192.168.0.1');
}
public function cacheHas()
{
//has
//判断key 是否存在
if(Cache::has('name')){
$val = Cache::get('name');
dd($val);
}else{
dd('null');
}
}
public function cachePull()
{
//pull
//取出后 删除(类似闪存)
$val = Cache::pull('name');
dd($val);
}
public function cacheForget()
{
//forget
//删除成功 true 否则false
$bool = Cache::forget('name');
dd($bool);
}
}
End
这个人暂时没有 freestyle