/** * @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'); }
public function restore() { //soft delete undo's $result = parent::restore(); Cache::tags(Config::get('entrust.permission_role_table'))->flush(); return $result; }
public function onTagsFlush() { $tags = $this->controller->getDefinitionOption('cache.tags', array()); foreach ($tags as $tag) { Cache::tags($tag)->flush(); } }
/** * 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); }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); Feedback::created(function ($item) { Cache::tags('feedbacks')->flush(); $this->dispatch(new SentenceProcessing($item)); }); Feedback::updated(function ($item) { Cache::tags('feedbacks')->flush(); }); Feedback::deleted(function ($item) { Cache::tags('feedbacks')->flush(); }); Comment::saved(function ($item) { Cache::tags('comments')->flush(); }); Comment::saved(function ($item) { Cache::tags('comments')->flush(); }); Sentence::saved(function ($item) { if ($item->feedback) { $item->feedback->calculateProbabilities(); } }); }
public function restore() { //soft delete undo's $result = parent::restore(); Cache::tags(Config::get('tron.role_user_table'))->flush(); return $result; }
/** * 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(); }
public function restore() { //soft delete undo's parent::restore(); Cache::tags('permission_section_users')->flush(); Cache::tags('role_user')->flush(); }
/** * Gets the cache engine instance. This method is used when the cache is referenced * with tags. In some cases like if the active cache driver is file, then the tags * method does not work and throws exception. * * @param array $cacheTags * @return mixed */ protected static function getCacheInstance(array $cacheTags) { try { return Cache::tags($cacheTags); } catch (\ErrorException $e) { return Cache::getFacadeRoot(); } }
public static function remember($key, $callback) { if (!Cache::has($key)) { $value = $callback(); Cache::tags(self::TAG)->put($key, $value, 60); } return Cache::tags(self::TAG)->get($key); }
public function getSystemConfig($field) { if (empty($value = Cache::tags(self::REDIS_SYSTEM_CONFIG)->get(self::REDIS_SYSTEM_CONFIG . $field))) { $value = self::select('system_value')->where('system_key', $field)->pluck('system_value'); Cache::tags(self::REDIS_SYSTEM_CONFIG)->put(self::REDIS_SYSTEM_CONFIG . $field, $value, config('site')['redis_cache_time']); } return $value; }
public function restore() { //soft delete undo's parent::restore(); if (Cache::getStore() instanceof TaggableStore) { Cache::tags(Config::get('entrust.role_user_table'))->flush(); } }
/** * Find a model by its primary key. * * @param array $ids * @param array $columns * * @return \Illuminate\Database\Eloquent\Collection */ public function findMany($ids, $columns = ['*']) { if (empty($ids)) { return $this->model->newCollection(); } return $this->model->newCollection(Cache::tags($this->model->getTable())->rememberMany($ids, $this->model->cacheExpiry, function ($ids) use($columns) { return parent::findMany($ids, $columns)->all(); })); }
public function restore() { //soft delete undo's if (!parent::restore()) { return false; } Cache::tags(Config::get('entrust.permission_role_table'))->flush(); return true; }
protected function setCache($shareCount) { $minutes = config('yaro.soc-share.cache_minutes'); if (!$minutes) { return null; } $key = $this->provider . '.' . md5(serialize($this->options)); return Cache::tags('soc-share')->put($key, $shareCount, $minutes); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $feedbacks = Cache::tags(['feedbacks', 'index', 'comments'])->get('feedbacks.index'); if (!$feedbacks) { $feedbacks = Feedback::with('status', 'visibility', 'comments')->get()->sortBy('created_at'); Cache::tags(['feedbacks', 'index', 'comments'])->put('feedbacks.index', $feedbacks, 1); } return view('backend.feedbacks.index', ['feedbacks' => $feedbacks]); }
public static function forget($id) { $key = self::key_cache($id); if (Cache::tags(self::getModelName())->has($key)) { Cache::tags(self::getModelName())->forget($key); //laravel-topka Cache::tags(self::getCacheModelName())->forget($key); } }
public function index() { $feedbacks = Cache::tags(['feedbacks', 'index', 'notClosed', 'comments'])->get('feedbacks.index.notClosed'); if (!$feedbacks) { $feedbacks = Feedback::with('status', 'visibility', 'comments')->isNotStatus('closed')->get()->sortByDesc(function ($feedback, $key) { return $feedback->probabilities[0]; }); Cache::tags(['feedbacks', 'index', 'notClosed', 'comments'])->put('feedbacks.index.notClosed', $feedbacks, 1); } return view('backend.dashboard', ['feedbacks' => $feedbacks]); }
public function restore() { //soft delete undo's if (!parent::restore()) { return false; } if (Cache::getStore() instanceof TaggableStore) { Cache::tags(Config::get('entrust.permission_role_table'))->flush(); } return true; }
/** * Cache the roles * * @return mixed */ public function cachedPermissions() { if ($this->isTagCacheAllowed()) { $primaryKeyName = $this->primaryKey; $cacheKey = 'permissions_for_role' . $this->{$primaryKeyName}; return Cache::tags($this->cacheName)->remember($cacheKey, 60, function () { return $this->permissions()->get(); }); } return $this->permissions()->get(); }
/** * Get the next command in queue. * * @return string */ public function next() { $this->getQueue(); if (count($this->queue)) { $key = array_shift($this->queue); $cmd = Cache::tags($this->queue_name)->get($key); Cache::tags($this->queue_name)->forget($key); $this->applyQueue(); return $cmd; } return null; }
/** * The "booting" method of the model. */ public static function boot() { parent::boot(); static::updated(function ($model) { Cache::tags($model->getTable())->forget($model->{$model->getKeyName()}); }, -1); static::saved(function ($model) { Cache::tags($model->getTable())->forget($model->{$model->getKeyName()}); }, -1); static::deleted(function ($model) { Cache::tags($model->getTable())->forget($model->{$model->getKeyName()}); }, -1); }
protected function registerEloquentEvents() { // Flush Elegant cache when anything changes for models registered by Elegant Event::listen('eloquent.*', function ($caller) { $callerClass = get_class($caller); if (!in_array($callerClass, ElegantConfig::getModelsAsClassNames())) { return; } if (in_array(Event::firing(), ['eloquent.saved', 'eloquent.deleted', 'eloquent.updated', 'eloquent.created']) && $this->cacheIsTaggable()) { Cache::tags('elegant-' . Support\ElegantModel::normalizeClassName($callerClass))->flush(); } }); }
public function banners() { $results = Cache::tags(array('banners'))->remember('banners', 10, function () { $this_time = date("Y-m-d G:i:00"); $results = DB::select(DB::raw("SELECT banners.* FROM\r\n banners\r\n\r\n WHERE\r\n id_banners_platform = '" . $this->id . "' and\r\n path_file != '' and\r\n is_show = 1 and\r\n ((show_start < '{$this_time}' or show_finish> '{$this_time}') or show_finish = '0000-00-00 00:00:00' or is_show_all='1') ")); return $results; }); shuffle($results); if (isset($results[0])) { return $results[0]; } return false; }
/** * Boot the user model * Attach event listener to remove the many-to-many records when trying to delete * Will NOT delete any records if the user model uses soft deletes. * * @return void|bool */ public static function bootEntrustUserTrait() { $flushCache = function () { if (Cache::getStore() instanceof TaggableStore) { Cache::tags(Config::get('entrust.permission_role_table'))->flush(); } }; static::restored($flushCache); static::deleted($flushCache); static::saved($flushCache); static::deleting(function ($user) { if (!method_exists(Config::get('auth.model'), 'bootSoftDeletes')) { $user->roles()->sync([]); } return true; }); }
public function handle($request, Closure $next) { $uri = $request->path(); preg_match_all("/(.*?)\\//", $uri, $raw); if (isset($raw[1][0])) { $tag = $raw[1][0]; } else { $tag = $uri; } if (Cache::tags($tag)->has($uri)) { return response(Cache::tags($tag)->get($uri))->header('Content-Type', 'application/json')->header('Access-Control-Allow-Origin', '*'); } try { $response = $next($request); Cache::tags($tag)->put($uri, $response->getContent(), 5); } catch (FileNotFoundException $e) { $response = response()->json(['result' => 'error', 'reason' => 'data not found.']); } return $response->header('Content-Type', 'application/json')->header('Access-Control-Allow-Origin', '*'); }
/** * Generates and outputs a new PAC based on a given IP. * * This is going to be used on devices that don't allow real time PAC generation. * * @param Request $req * * @return string the generated PAC */ public function generatePAC(Request $req) { $proxy_addr = Input::get('proxy_addr', $this->getProxy($req)); if (is_array($proxy_addr)) { $proxy_addr = $proxy_addr['host'] . ":" . $proxy_addr['port']; } // check for cache if (Cache::tags(['generate_pac'])->has($proxy_addr)) { return new Response(Cache::tags(['generate_pac'])->get($proxy_addr), 200, ['Content-Type' => 'application/x-ns-proxy-autoconfig']); } $pac = "function FindProxyForURL(url, host) {\n"; foreach (SitesController::getAllSites() as $site) { $pac .= " if (host == \"{$site}\" || host == \"www.{$site}\") { \n"; $pac .= " return 'PROXY " . e($proxy_addr) . "';\n"; $pac .= " }\n"; } $pac .= " return 'DIRECT';\n"; $pac .= "}"; Cache::tags(['generate_pac'])->put($proxy_addr, $pac, 3600); // Store it for a day return new Response($pac, 200, ['Content-Type' => 'application/x-ns-proxy-autoconfig']); }
/** * Load the inventory for a Steam ID * * @param integer $steamId * @return Json */ public function loadInventory($steamId, $appId = 730, $contextId = 2) { $rawInventory = Cache::tags([$this->cacheTag, $appId])->remember($steamId, $this->cacheTime, function () use($steamId, $appId, $contextId) { return $this->fetchRawSteamInventory($steamId, $appId, $contextId); }); $this->success = $rawInventory['success']; if ($this->success == false) { $this->error = $rawInventory['Error'] ? $rawInventory['Error'] : ''; return false; } $this->inventory = collect($rawInventory['rgInventory'])->map(function ($item) use($contextId, $rawInventory) { $item['contextid'] = $contextId; if (!isset($rawInventory['rgDescriptions'][$item['classid'] . '_' . $item['instanceid']])) { return $item; } return array_merge($item, $rawInventory['rgDescriptions'][$item['classid'] . '_' . $item['instanceid']]); })->map(function ($item) use($rawInventory) { if (!isset($rawInventory['rgCurrency'][$item['classid'] . '_' . $item['instanceid']])) { return $item; } return array_merge($item, $rawInventory['rgCurrency'][$item['classid'] . '_' . $item['instanceid']]); }); return true; }
/** * Get Leaves * * Retrieves and caches all descendant nodes without children. * @return Illuminate\Support\Collection */ public function getLeaves() { return Cache::tags($this->formatTag('leaves'))->remember($this->getCacheId('leaves'), self::CACHE_LONG, function () { return $this->leaves()->get(); }); }
/** * Clear necessary caches after top off purchase */ private function clearTopOffCache() { //Bust this cache so we see the new cap Cache::tags("usage_based_billing_policy_details")->forget(get_user()->account_id); $billingController = new BillingController(); $billingController->clearBillingCache(); }