本文整理汇总了PHP中Illuminate\Support\Facades\Cache::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::get方法的具体用法?PHP Cache::get怎么用?PHP Cache::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Cache
的用法示例。
在下文中一共展示了Cache::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* @param Query $query
* @return Result|null
*/
private function get($query)
{
if (!$this->cache) {
return null;
} elseif (!($serialized = $this->cache->get($query->getHashKey()))) {
return null;
}
return unserialize($serialized);
}
示例2: handle
/**
* @inheritdoc
*/
public function handle($arguments)
{
if (!Cache::has('site-' . $arguments)) {
$this->replyWithMessage("Não foi encontrado nenhum site com esse argumento.");
return;
}
$site = Cache::get('site-' . $arguments);
// Validate if the URL isn't on the database yet
if (Site::where('url', '=', $site)->first() != null) {
$this->replyWithMessage("O site {$site} já se encontra na base de dados.");
return;
}
$site_obj = new Site();
$site_obj->url = $site;
$site_obj->save();
$this->replyWithMessage($site . " foi adicionado à base de dados.", true);
// Notify the sitesbloqueados.pt about the new site
$url = 'https://sitesbloqueados.pt/wp-json/ahoy/refresh';
$cmd = "curl -X GET -H 'Content-Type: application/json'";
$cmd .= " " . "'" . $url . "'";
$cmd .= " > /dev/null 2>&1 &";
exec($cmd, $output);
// Flush the PAC cache
Cache::tags(['generate_pac'])->flush();
// Remove the cache
Cache::forget('site-' . $arguments);
Cache::forget('site-list');
}
示例3: handle
/**
* @throws \Exception
*/
public function handle()
{
$name = $this->argument('name');
$isUserRestrict = $this->confirm('User restricted ?', false);
$author = $this->ask("Your username", Cache::get('developer.username', ''));
Cache::forever('developer.username', $author);
$generator = new Generator($name, $isUserRestrict, $author);
$templateData = $generator->getTemplateData();
$files = $generator->getFiles();
$belongToRelations = $this->getRelation('BelongTo');
if ($isUserRestrict) {
$belongToRelations[] = 'user';
}
$belongToRelations = array_unique($belongToRelations);
$manyToManyRelations = $this->getRelation('ManyToMany');
$manyToManyRelations = array_unique($manyToManyRelations);
$fields = $this->getFields();
$this->summary($templateData, $isUserRestrict);
$this->fieldsSummary($fields);
$this->generate($generator, $fields, ['belongTo' => $belongToRelations, 'manyToMany' => $manyToManyRelations]);
$this->runComposerDumpAutoload();
$this->migrateDatabase();
$this->generateDocumentation();
$this->info("");
$this->info("What you need to do now ?");
$this->info("\t [] Add Acl/Scope to your route in routes.php");
$this->info("\t [] Fill data provider for " . $files['controllerTest']);
$this->info("\t [] Fill data provider for " . $files['repositoryTest']);
}
示例4: _fetchDataset
private function _fetchDataset($filter)
{
return Cache::get($this->key, function () use($filter) {
Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
return $data;
});
}
示例5: tableToArray
/**
* Return a simple list of entries in the table.
*
* May cache the results for up to 60 minutes.
*
* @return array of Fluent objects
*/
public static function tableToArray()
{
$me = new static();
$cache_key = $me->cacheKey();
// Return the array from the cache if it is present.
if (Cache::has($cache_key)) {
return (array) Cache::get($cache_key);
}
// Otherwise put the results into the cache and return them.
$results = [];
$query = static::all();
// If the current model uses softDeletes then fix the
// query to exclude those objects.
foreach (class_uses(__CLASS__) as $traitName) {
if ($traitName == 'SoftDeletes') {
$query = static::whereNull('deleted_at')->get();
break;
}
}
/** @var Cacheable $row */
foreach ($query as $row) {
$results[$row->getIndexKey()] = $row->toFluent();
}
Cache::put($cache_key, $results, 60);
return $results;
}
示例6: get
/**
* Returns cached data
*
* @param string $key
* @return mixed
*/
public static function get($key)
{
if (!isset(static::$cache[$key])) {
static::$cache[$key] = parent::get($key);
}
return static::$cache[$key];
}
示例7: getCachedAssemblyItems
/**
* Returns the current cached items assembly if
* it exists inside the cache. Returns false
* otherwise.
*
* @return bool|\Illuminate\Database\Eloquent\Collection
*/
public function getCachedAssemblyItems()
{
if ($this->hasCachedAssemblyItems()) {
return Cache::get($this->getAssemblyCacheKey());
}
return false;
}
示例8: check
/**
* Check the token
*
* @param string $token
* @return boolean
*/
public function check($token)
{
if (!Cache::has($this->getCacheKey())) {
return false;
}
return Cache::get($this->getCacheKey()) === $token;
}
示例9: isAdmin
public function isAdmin()
{
if (Cache::has('role.' . Auth::id()) && Cache::get('role.' . Auth::id()) === 'admin') {
return true;
}
return false;
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Cache::get('role.' . Auth::id()) == 'admin') {
return $next($request);
}
abort(404);
}
示例11: compose
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
if (!Cache::get('popular_categories')) {
Cache::put('popular_categories', $this->categories->getPopular(), 60);
}
$view->with('popular_categories', Cache::get('popular_categories'));
}
示例12: fetch
public function fetch(Route $route, Request $request)
{
$key = self::makeCacheKey($request->url());
if (Cache::has($key)) {
return Cache::get($key);
}
}
示例13: compose
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
if (!Cache::get('recent_posts')) {
Cache::put('recent_posts', $this->posts->getAll('published', null, 'published_at', 'desc', 5), 10);
}
$view->with('recent_posts', Cache::get('recent_posts'));
}
示例14: getTimestampMigrationName
/**
* @return string
*/
protected function getTimestampMigrationName()
{
if (!Cache::has(static::CACHENAME)) {
Cache::forever(static::CACHENAME, date('Y_m_d_His') . '_' . $this->getMigrationName());
}
return Cache::get(static::CACHENAME);
}
示例15: currentWebsiteData
/**
* Determine the current website data.
*
* Returns null if the web site is not found in the websites table.
*
* @return array
*/
public static function currentWebsiteData()
{
static $current_data;
$BASE_URL = static::currentServerName();
$cache_key = 'website-data.' . $BASE_URL;
// Get the current ID from the cache if it is present.
if (empty($current_data)) {
if (Cache::has($cache_key)) {
return Cache::get($cache_key);
}
}
// If the cache doesn't have it then get it from the database.
if (empty($current_data)) {
// Have to do this using a raw query because Laravel doesn't INSTR.
try {
/** @var Website $result */
$result = static::whereRaw("INSTR('" . $BASE_URL . "', `http_host`) > 0")->orderBy(DB::raw('LENGTH(`http_host`)'), 'desc')->first();
if (empty($result)) {
$current_data = null;
} else {
$current_data = $result->toArray();
}
Cache::put($cache_key, $current_data, 60);
} catch (\Exception $e) {
$current_data = null;
}
}
return $current_data;
}