本文整理汇总了PHP中Illuminate\Support\Facades\Cache::store方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::store方法的具体用法?PHP Cache::store怎么用?PHP Cache::store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Cache
的用法示例。
在下文中一共展示了Cache::store方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param CoreInterface $core
*/
public function __construct(CoreInterface $core)
{
$this->core = $core;
$cache = IlluminateCache::store($this->getCacheStore());
if ($tags = $this->getCacheTags()) {
$cache = $cache->tags($tags);
}
$this->cache = $cache;
}
示例2: __construct
public function __construct(Database $database, $cacheName = null, $lifetime = null)
{
$this->database = $database;
if ($cacheName) {
$this->cache = Cache::store($cacheName);
$this->lifetime = $lifetime;
} else {
$this->cache = null;
$this->lifetime = 0;
}
}
示例3: getArticle
public function getArticle($id)
{
return Cache::store($this->store)->rememberForever($id, function () use($id) {
$article_model = new Articles();
$article = $article_model->published()->getById($id)->with('tags', 'category')->first();
$data = ['id' => $article->id, 'title' => $article->title, 'curl' => $article->curl, 'keywords' => $article->meta_keywords, 'description' => $article->meta_description, 'content' => $article->content, 'created_at' => $article->created_at, 'updated_at' => $article->updated_at, 'is_comments' => $article->comments_enable, 'category' => ['id' => $article->category->id, 'name' => $article->category->name, 'curl' => $article->category->curl]];
foreach ($article->tags as $tag) {
$data['tags'][] = ['id' => $tag->id, 'name' => $tag->name, 'curl' => $tag->curl];
}
return $data;
});
}
示例4: getCommentsByIdArticle
public function getCommentsByIdArticle($id)
{
return Cache::store($this->store)->rememberForever($id, function () use($id) {
$data = [];
$comments_model = new CommentsModel();
$comments = $comments_model->published()->commentsByArticleId($id)->orderByParam()->get();
foreach ($comments as $coment) {
$data[] = ['id' => $coment->id, 'user' => $coment->user, 'message' => $coment->message, 'answer' => $coment->answer];
}
return $data;
});
}
示例5: register
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$config = (new GeoCode\Config())->initFromArray(config('services.geo_code'));
$this->app->singleton(GeoCode\Manager::class, function ($app) use($config) {
$req = new GeoCode\Http\Guzzle(['base_uri' => $config->apiUrl, 'verify' => false]);
return new GeoCode\Manager($config, $req, Cache::store($config->cacheDriver));
});
$this->app->bind(GeoCode\Response::class, function ($app) use($config) {
return new GeoCode\Response($config->apiOutput, '');
});
$this->app->instance(GeoCode\Config::class, $config);
}
示例6: index
public function index()
{
$navFlag = 'blog';
$newPosts = Cache::store('redis')->remember($this->indexPostsKey, 30, function () {
$articles = [];
$list = Wp::type('post')->status('publish')->orderBy('post_date', 'desc')->take(17)->get();
foreach ($list as $item) {
$articles[] = ['url' => $item->url, 'post_title' => $item->post_title, 'post_date' => $item->post_date->format('Y-m-d')];
}
return $articles;
});
return View('index/blog', compact('newPosts', 'navFlag'));
}
示例7: getAll
public function getAll()
{
return Cache::store('prevAll')->rememberForever($this->page, function () {
//методанные
$items['title'] = 'Главная';
$items['keywords'] = 'блог, разработка, php, главная';
$items['description'] = 'Главная страница блога начинающего backend разработчика. Заходите.';
//превьюхи
$articles = new Articles();
$articles = $articles->published()->orderByParam()->with('tags', 'category')->paginate($this->countPage);
//Превьюхи в нужном формате
$items['articles'] = $this->createArrPreviews($articles);
return $this->createLengthAwarePaginator($articles, $items);
});
}
示例8: getCategoryNavigate
public function getCategoryNavigate()
{
return Cache::store($this->store)->rememberForever('menu:cat', function () {
$cat_cl = new Categories();
$categories = $cat_cl->getAllCategory();
foreach ($categories as $key => $category) {
$date[$key]['id'] = $category->id;
$date[$key]['name'] = $category->name;
$date[$key]['curl'] = $category->curl;
//Получаем кол-во новостей в каждой категории
$date[$key]['count_article'] = $category->getArticlesByCondition()->count();
}
return $date;
});
}
示例9: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$blockIps = Cache::get('block_ip', function () {
$blockIps = BlockIp::all()->toArray();
Cache::store('redis')->put('block_ip', $blockIps, 10);
return $blockIps;
});
if ($blockIps) {
foreach ($blockIps as $ip) {
if (starts_with($request->getClientIp(), $ip['ip_address'])) {
abort(404);
}
}
}
return $next($request);
}
示例10: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Cache::store('aside')->flush();
$this->info('Asides cleared');
Cache::store('prevAll')->flush();
$this->info('Prev. cleared');
Cache::store('prevCat')->flush();
$this->info('Prev./cat. cleared');
Cache::store('prevTag')->flush();
$this->info('Prev./tag. cleared');
Cache::store('article')->flush();
$this->info('Articles cleared');
Cache::store('comments')->flush();
$this->info('Comments cleared');
$this->info('All automatic cache cleared');
}
示例11: gitCommitHistory
/**
* Github上提交版本历史
* @method POST
* @return string
*/
public function gitCommitHistory()
{
$client = new Client(['base_uri' => 'https://api.github.com/']);
$uri = 'repos/tanteng/tanteng.me/commits';
$query['client_id'] = Config::get('github.client_id');
$query['client_secret'] = Config::get('github.client_secret');
try {
$result = Cache::store('redis')->remember('git.commit.history', 60, function () use($client, $uri, $query) {
return $client->get($uri, $query)->getBody()->getContents();
});
} catch (ConnectException $e) {
return json_encode(['result' => 1001, 'msg' => '请求超时!', 'data' => $e->getMessage()]);
}
$result = json_decode($result, true);
$commitHistory = [];
foreach ($result as $item) {
$commitHistory[] = ['message' => $item['commit']['message'], 'datetime' => date('Y-m-d H:i:s', strtotime($item['commit']['committer']['date']))];
}
return json_encode(['result' => 0, 'msg' => '请求成功!', 'data' => $commitHistory]);
}
示例12: __construct
/**
* Assign dependencies.
*/
public function __construct()
{
$this->cache = Cache::store();
}
示例13: flushCache
public function flushCache($store)
{
Cache::store($store)->flush();
}