本文整理汇总了PHP中Illuminate\Support\Facades\Cache类的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if ($this->option('tracks') === 'all') {
// Get all cacheable track files
$trackFiles = TrackFile::where('is_cacheable', true)->with('track.album')->get();
} else {
// Get all expired track files
$trackFiles = TrackFile::where('is_cacheable', true)->where('expires_at', '<=', Carbon::now())->with('track.album')->get();
}
// Delete above track files
if (count($trackFiles) === 0) {
$this->info('No tracks found. Exiting.');
} else {
if ($this->option('force') || $this->confirm(count($trackFiles) . ' cacheable track files found. Proceed to delete their files if they exist? [y|N]', false)) {
$count = 0;
foreach ($trackFiles as $trackFile) {
// Set expiration to null (so can be re-cached upon request)
$trackFile->expires_at = null;
$trackFile->update();
// Delete file if exists
if (File::exists($trackFile->getFile())) {
$count++;
File::delete($trackFile->getFile());
$this->info('Deleted ' . $trackFile->getFile());
}
// Remove the cached file size for the album
Cache::forget($trackFile->track->album->getCacheKey('filesize-' . $trackFile->format));
}
$this->info($count . ' files deleted. Deletion complete. Exiting.');
} else {
$this->info('Deletion cancelled. Exiting.');
}
}
}
示例2: show
public function show()
{
$options = Config::get('onepager.options');
$progressBar = Cache::get('progressBar', function () {
$c = curl_init('https://www.startnext.com/sanktionsfrei/widget/?w=200&h=300&l=de');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($c);
if (curl_error($c)) {
die(curl_error($c));
}
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
$percent = 0;
if ($status == 200) {
$crawler = new Crawler();
$crawler->addHTMLContent($html, 'UTF-8');
// get the percentage for the progressbar
$styleString = $crawler->filter('.bar.bar-1')->attr('style');
$stringArray = explode(':', $styleString);
$percent = substr($stringArray[1], 0, -2);
// get the text for the progressbar
$textArray = $crawler->filter('.status-text span')->extract(['_text']);
}
return ['percent' => $percent, 'progressText' => $textArray[0]];
}, 5);
return view('home', ['options' => $options, 'percent' => $progressBar['percent'], 'progressText' => $progressBar['progressText']]);
}
示例3: getClear
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getClear()
{
// Cache::forget('settings');
// Cache::forget('popular_categories');
Cache::flush();
return redirect()->back()->withSuccess('Cache Cleared!');
}
示例4: putAll
/**
* Handle permissions change
*
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function putAll(Request $request)
{
$permissions = Permission::all();
$input = array_keys($request->input('permissions'));
try {
DB::beginTransaction();
$permissions->each(function ($permission) use($input) {
if (in_array($permission->id, $input)) {
$permission->allow = true;
} else {
$permission->allow = false;
}
$permission->save();
});
DB::commit();
flash()->success(trans('permissions.save_success'));
} catch (\Exception $e) {
var_dump($e->getMessage());
die;
flash()->error(trans('permissions.save_error'));
}
try {
Cache::tags(['permissions'])->flush();
} catch (\Exception $e) {
Cache::flush();
}
return redirect()->back();
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$fabricantes = Cache::remember('fabricantes', 15 / 60, function () {
return Fabricante::simplePaginate(15);
});
return response()->json(['siguiente' => $fabricantes->nextPageUrl(), 'anterior' => $fabricantes->previousPageUrl(), 'datos' => $fabricantes->items()], 200);
}
示例6: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (app()->environment() == 'local') {
Cache::tags('views')->flush();
}
return $next($request);
}
示例7: getLatestBans
/**
* Gets the latest bans
* @param string $cacheKey Caching key to use
* @param integer $ttl Cache for X minutes
* @return array
*/
public function getLatestBans($cacheKey = 'bans.latest', $ttl = 1)
{
$bans = Cache::remember($cacheKey, $ttl, function () {
return Ban::with('player', 'record')->latest(30)->get()->toArray();
});
return $bans;
}
示例8: 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);
}
示例9: 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);
}
示例10: isAdmin
public function isAdmin()
{
if (Cache::has('role.' . Auth::id()) && Cache::get('role.' . Auth::id()) === 'admin') {
return true;
}
return false;
}
示例11: schedule
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
Cache::put('last-cron', new Carbon(), 5);
})->everyMinute();
$schedule->command('inspire')->hourly();
}
示例12: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$key = $this->buildCacheKey($request);
return Cache::remember($key, static::CACHE_MINUTES, function () use($request, $next) {
return $next($request);
});
}
示例13: update
public function update($id)
{
try {
$groups = Cache::get('admin.adkats.special.groups');
$player = Special::findOrFail($id);
foreach ($groups as $group) {
if ($group['group_key'] == Input::get('group')) {
$newGroup = $group['group_name'];
break;
}
}
$player->player_group = Input::get('group');
$player->save();
if (is_null($player->player)) {
$soldierName = $player->player_identifier;
} else {
$soldierName = $player->player->SoldierName;
}
$message = sprintf('%s group has been changed to %s.', $soldierName, $newGroup);
return MainHelper::response(null, $message);
} catch (ModelNotFoundException $e) {
$message = sprintf('No player found with special id of %u', $id);
return MainHelper::response(null, $message, 'error', 404);
} catch (Exception $e) {
return MainHelper::response($e, $e->getMessage(), 'error', 500);
}
}
示例14: _fetchDataset
private function _fetchDataset($filter)
{
return Cache::get($this->key, function () use($filter) {
Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
return $data;
});
}
示例15: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!Cache::has('session.key')) {
return redirect('/')->with('error', 'You must log in in order to view that page.');
}
return $next($request);
}