【Laravel3.0.0源码阅读分析】缓存驱动类driver.php
发布日期:2021-06-30 20:44:51
浏览次数:2
分类:技术文章
本文共 1867 字,大约阅读时间需要 6 分钟。
* // Get an item from the cache driver * $name = Cache::driver('name'); * * // Return a default value if the requested item isn't cached * $name = Cache::get('name', 'Taylor'); * * * @param string $key * @param mixed $default * @return mixed */ public function get($key, $default = null) { return ( ! is_null($item = $this->retrieve($key))) ? $item : value($default); } /** * Retrieve an item from the cache driver. * 从缓存驱动程序中检索项 * @param string $key * @return mixed */ abstract protected function retrieve($key); /** * Write an item to the cache for a given number of minutes. * 向缓存中写入一个带有过期时间的项 ** // Put an item in the cache for 15 minutes * Cache::put('name', 'Taylor', 15); *
* * @param string $key * @param mixed $value * @param int $minutes * @return void */ abstract public function put($key, $value, $minutes); /** * Get an item from the cache, or cache and return the default value. * 从缓存中获取一个项,或者缓存并返回默认值。 ** // Get an item from the cache, or cache a value for 15 minutes * $name = Cache::remember('name', 'Taylor', 15); * * // Use a closure for deferred execution * $count = Cache::remember('count', function() { return User::count(); }, 15); *
* * @param string $key * @param mixed $default * @param int $minutes * @return mixed */ public function remember($key, $default, $minutes) { if ( ! is_null($item = $this->get($key, null))) return $item; $this->put($key, $default = value($default), $minutes); return $default; } /** * Delete an item from the cache. * 从缓存中删除一个项 * @param string $key * @return void */ abstract public function forget($key); /** * Get the expiration time as a UNIX timestamp. * 以 UNIX 时间戳的形式获取到期时间。 * @param int $minutes * @return int */ protected function expiration($minutes) { return time() + ($minutes * 60); }}
github地址:
转载地址:https://liushilong.blog.csdn.net/article/details/117429177 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月15日 15时17分37秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
记一次曲折的Debug经历
2019-04-30
Impala支持Google云存储开发笔记
2019-04-30
如何在Apache JIRA中搜索issue
2019-04-30
scrapy 排错记录
2019-04-30
ACM路上的一大失误
2019-04-30
HDOJ2049 不容易系列之(4)——考新郎
2019-04-30
CodeForces 248B - Chilly Willy - 找规律
2019-04-30
POJ-2418 Hardwood Species(Trie树)(map)
2019-04-30
HDU-4300 Clairewd’s message + 4333(扩展KMP)
2019-04-30
HDU 1592 Half of and a Half(高精度)
2019-04-30
POJ-3304 Segments(计算几何)
2019-04-30
UVA-11538 Chess Queen(数学)
2019-04-30
UVA-11401 Triangle Counting(数学优化)
2019-04-30
Codeforces Round #369 (Div. 2)
2019-04-30
UVA 11426 GCD - Extreme (II)(欧拉函数)
2019-04-30
HDU-2838 Cow Sorting(树状数组)
2019-04-30
POJ-2299 Ultra-QuickSort(树状数组)(离散化)
2019-04-30
基于SSM的兼职论坛系统的设计与实现
2019-04-30
基于java的图书管理系统的设计与实现
2019-04-30