作者:nsystem
项目:Pony.f
/**
* 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.');
}
}
}
作者:johannesponade
项目:Onepage
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']]);
}
作者:ambarsetyawa
项目:brewsk
/**
* 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!');
}
作者:Denniskevi
项目:Laravel5Starte
/**
* 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();
}
作者:osvaldin
项目:RESTful-AP
/**
* 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);
}
作者:steveaz
项目:rudoll
/**
* 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);
}
作者:R3alflas
项目:BFAdminC
/**
* 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;
}
作者:uusa3
项目:turnk
/**
* 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);
}
作者:jayaregalinad
项目:commo
/**
* @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);
}
作者:uusa3
项目:turnk
public function isAdmin()
{
if (Cache::has('role.' . Auth::id()) && Cache::get('role.' . Auth::id()) === 'admin') {
return true;
}
return false;
}
作者:atrauzz
项目:laravel-drydoc
/**
* 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();
}
作者:hussainwe
项目:drupal-stat
/**
* 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);
});
}
作者:BP4
项目:BFAdminC
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);
}
}
作者:skiz
项目:freshdeskreportin
private function _fetchDataset($filter)
{
return Cache::get($this->key, function () use($filter) {
Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
return $data;
});
}
作者:pasadinha
项目:sirs-projec
/**
* 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);
}
作者:ambarsetyawa
项目:brewsk
/**
* 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'));
}
作者:alfred-nutile-in
项目:webhook
public static function boot()
{
parent::boot();
Webhook::creating(function ($results) {
Cache::forget('webhooks');
});
}
作者:RichJones2
项目:TimeTra
public function put(Route $route, Request $request, Response $response)
{
$key = $this->makeCacheKey($request->url());
if (!Cache::has($key)) {
Cache::put($key, $response->getContent(), 10);
}
}
作者:staciewilhel
项目:denver-member-trackin
/**
* Setup for Google API authorization to retrieve directory data
*/
function __construct()
{
// set config options
$clientId = Config::get('google.client_id');
$serviceAccountName = Config::get('google.service_account_name');
$delegatedAdmin = Config::get('google.admin_email');
$keyFile = base_path() . Config::get('google.key_file_location');
$appName = Config::get('google.app_name');
// array of scopes
$scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.readonly');
// Create AssertionCredentails object for use with Google_Client
$creds = new \Google_Auth_AssertionCredentials($serviceAccountName, $scopes, file_get_contents($keyFile));
// set admin identity for API requests
$creds->sub = $delegatedAdmin;
// Create Google_Client to allow making API calls
$this->client = new \Google_Client();
$this->client->setApplicationName($appName);
$this->client->setClientId($clientId);
$this->client->setAssertionCredentials($creds);
if ($this->client->getAuth()->isAccessTokenExpired()) {
$this->client->getAuth()->refreshTokenWithAssertion($creds);
}
Cache::forever('service_token', $this->client->getAccessToken());
// Set instance of Directory object for making Directory API related calls
$this->service = new \Google_Service_Directory($this->client);
}
作者:DraperStudi
项目:Laravel-Countrie
/**
* Bootstrap the application services.
*/
public function boot()
{
parent::boot();
$this->publishMigrations();
$app = $this->app;
if ($app->bound('form')) {
$app->form->macro('selectCountry', function ($name, $selected = null, $options = []) use($app) {
$countries = Cache::rememberForever('brianfaust.countries.select.name.cca2', function () {
$records = Country::get(['name', 'cca2']);
$countries = new Collection();
$records->map(function ($item) use(&$countries) {
$countries[$item['cca2']] = $item['name']['official'];
});
return $countries->sort();
});
return $app->form->select($name, $countries, $selected, $options);
});
$app->form->macro('selectCountryWithId', function ($name, $selected = null, $options = []) use($app) {
$countries = Cache::rememberForever('brianfaust.countries.select.id.cca2', function () {
$records = Country::get(['name', 'id']);
$countries = new Collection();
$records->map(function ($item) use(&$countries) {
$countries[$item['id']] = $item['name']['official'];
});
return $countries->sort();
});
return $app->form->select($name, $countries, $selected, $options);
});
}
}