/** * */ public function __call($method, $params) { if (!method_exists($this->repository, $method)) { throw new RepositoryException("Method {$method} not found on repository"); } if ($this->skipCache === true || config('laravel-database.cache') === false) { return call_user_func_array(array($this->repository, $method), $params); } else { if (empty($this->key)) { $this->cacheKey($this->generateKey($method, $params)); } $key = $this->key; unset($this->key); if ($this->refreshCache) { $this->cache->forget($key); $this->refreshCache = false; } if (empty($this->lifetime)) { $this->cacheLifetime($this->repository->getModel()->cacheLifetime()); } $lifetime = $this->lifetime; unset($this->lifetime); return $this->cache->remember($key, $lifetime, function () use($method, $params) { return call_user_func_array(array($this->repository, $method), $params); }); } }
public function update($id, array $attribute) { if ($this->model->update($id, $attribute)) { $this->cache->forget($this->getKey('all')); $this->cache->forget($this->getKey('id-' . $id)); } }
/** * @param bool $forget * * @return \Illuminate\Database\Eloquent\Collection|Role[]|null */ public function roles(bool $forget = false) { if ($forget === true) { return $this->cache->forget(self::ROLE_KEY); } return $this->cache->rememberForever(self::ROLE_KEY, function () { return app(Role::class)->with('permissions')->get(); }); }
/** * Query the Google Analytics Service with given parameters. * * @param string $viewId * @param \DateTime $startDate * @param \DateTime $endDate * @param string $metrics * @param array $others * * @return array|null */ public function performQuery(string $viewId, DateTime $startDate, DateTime $endDate, string $metrics, array $others = []) { $cacheName = $this->determineCacheName(func_get_args()); if ($this->cacheLifeTimeInMinutes == 0) { $this->cache->forget($cacheName); } return $this->cache->remember($cacheName, $this->cacheLifeTimeInMinutes, function () use($viewId, $startDate, $endDate, $metrics, $others) { return $this->service->data_ga->get("ga:{$viewId}", $startDate->format('Y-m-d'), $endDate->format('Y-m-d'), $metrics, $others); }); }
/** * @param $name * @param $arguments * @return mixed */ public function __call($name, $arguments) { /* * simple strategy: for any database altering method we do the following: * - call the parent method * - bust the cache */ $result = call_user_func_array([$this->menu, $name], $arguments); $this->cache->forget('menus'); return $result; }
public function handle() { try { $configs = $this->config->get('acl'); $this->permissionManager->deleteAllPermissions(); $this->cache->forget($configs['acl.permission_cache_key']); $this->cache->tags($configs['acl.user_permissions_cache_key'])->flush(); $this->info('All permissions are deleted from database and cache'); } catch (\Exception $e) { $this->error($e->getMessage()); } }
/** * Get the given documentation page. * * @param string $version * @param string $page * @return string */ public function get($version, $page) { // If the enviroment is local forget the cache if (app()->environment() == 'local') { $this->cache->forget('docs.' . $version . '.' . $page); } return $this->cache->remember('docs.' . $version . '.' . $page, 5, function () use($version, $page) { $path = base_path('resources/docs/' . $version . '/' . $page . '.md'); if ($this->files->exists($path)) { return $this->replaceLinks($version, markdown($this->files->get($path))); } return null; }); }
private function recountForums() { $this->info('Recounting forum counters...'); // We're calling the model directly to avoid caching issues $forums = Forum::all(); foreach ($forums as $forum) { // We need the topics later to calculate the post number and the last post $topics = Topic::where('forum_id', '=', $forum->id)->orderBy('created_at', 'desc'); $forum->num_topics = $topics->count(); $numPosts = 0; $lastPost = null; $lastPostUser = null; foreach ($topics->get() as $topic) { $numPosts += $topic->num_posts; // We can simply override this variable all the time. // The topics are sorted so the last time we override this we have our last post $lastPost = $topic->last_post_id; $lastPostUser = $topic->lastPost->user_id; } $forum->num_posts = $numPosts; $forum->last_post_id = $lastPost; $forum->last_post_user_id = $lastPostUser; $forum->save(); } // Override our old cache to populate our new numbers $this->cache->forever('forums.all', $forums); // We could also recache this cache but the recount tool is already busy // so probably better to leave it to the first user $this->cache->forget('forums.index_tree'); $this->info('Done' . PHP_EOL); }
/** * {@inheritdoc} */ public function save(CacheItemInterface $item) { $expiresAt = $this->getExpiresAt($item); if (!$expiresAt) { try { $this->repository->forever($item->getKey(), serialize($item->get())); } catch (Exception $exception) { return false; } return true; } $now = new DateTimeImmutable('now', $expiresAt->getTimezone()); $seconds = $expiresAt->getTimestamp() - $now->getTimestamp(); $minutes = (int) floor($seconds / 60.0); if ($minutes <= 0) { $this->repository->forget($item->getKey()); return false; } try { $this->repository->put($item->getKey(), serialize($item->get()), $minutes); } catch (Exception $exception) { return false; } return true; }
public function clear() { //clear database $this->storage->clear(); // clear cached options $this->cache->forget('weboap.options'); }
/** * Forget a rendered view. * * @param string $view * @param string $key */ public function forget($view, $key = null) { $cacheKey = $this->getCacheKeyForView($view, $key); if ($this->cacheIsTaggable) { $this->cache->tags($this->cacheKey)->forget($cacheKey); } $this->cache->forget($cacheKey); }
/** * Save the changes. * * @param \Illuminate\Database\Eloquent\Collection $saved * @param array $changes */ public function save($saved, array $changes) { $this->setSaved($saved); $this->saveInserted($changes['inserted']); $this->saveUpdated($changes['updated']); $this->saveDeleted($changes['deleted']); if ($this->isCached()) { $this->cache->forget($this->getCacheKey()); } }
/** * Forget current setting value. * * @param string $key * @return void */ public function forget($key) { $this->fire('forgetting', $key, [$key]); $generatedKey = $this->getKey($key); $this->repository->forget($generatedKey); if ($this->isCacheEnabled()) { $this->cache->forget($generatedKey); } $this->fire('forget', $key, [$key]); $this->context(null); }
/** * @param RepositoryEventBase $event */ public function handle(RepositoryEventBase $event) { try { $cleanEnabled = config("repository.cache.clean.enabled", true); if ($cleanEnabled) { $this->repository = $event->getRepository(); $this->model = $event->getModel(); $this->action = $event->getAction(); if (config("repository.cache.clean.on.{$this->action}", true)) { $cacheKeys = CacheKeys::getKeys(get_class($this->repository)); if (is_array($cacheKeys)) { foreach ($cacheKeys as $key) { $this->cache->forget($key); } } } } } catch (\Exception $e) { Log::error($e->getMessage()); } }
/** * Run the given event. * * @param \Illuminate\Contracts\Container\Container $container * @return void */ public function run(Container $container) { if ($this->withoutOverlapping) { $this->cache->put($this->mutexName(), true, 1440); } if (!$this->runInBackground) { $this->runCommandInForeground($container); } else { $this->runCommandInBackground(); } if ($this->withoutOverlapping) { $this->cache->forget($this->mutexName()); } }
/** * Flush the cache for this Model Object instance * * @param Model $model * @return void */ public function flush(Model $model) { // Assemble Cache Keys $keys[] = $this->resourceName . '.hash.' . $model->hash; $keys[] = $this->resourceName . '.id.' . $model->id; // Some keys will not be available on all models if ($this->model->isFillable('ref')) { $keys[] = $this->resourceName . '.ref.' . $model->ref; } // Clear the cache for the given keys foreach ($keys as $key) { $this->cache->forget($key); } }
/** * Remove the documentation cache. * * @param string $doc * @param string|null $version * @return void */ public function clearCache($doc, $version = null) { $this->docs = null; $this->cache->forget('docs.yml'); if ($version) { $versions = [$version]; } else { $versions = array_keys($this->getVersions($doc)); } foreach ($versions as $version) { $path = $this->getStoragePath($doc, $version); $pages = $this->files->files($path); foreach ($pages as $page) { $page = substr(basename($page), 0, -3); $this->cache->forget("{$doc}.{$version}.{$page}"); } } }
/** * Restore the field type column to cache. * * @param Blueprint $table */ public function restoreColumn(Blueprint $table) { // Skip if no column type. if (!$this->fieldType->getColumnType()) { return; } // Skip if the column doesn't exist. if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) { return; } // Translatable or no? $translatable = ends_with($table->getTable(), '_translations'); // Restore the data. $results = $this->cache->get(__CLASS__ . $this->fieldType->getColumnName()); foreach ($results as $result) { $result = (array) $result; $this->connection->table($table->getTable())->where($translatable ? 'entry_id' : 'id', array_pull($result, 'id'))->update($result); } $this->cache->forget(__CLASS__ . $this->fieldType->getColumnName()); }
/** * Delete an item from the storage if it exists. * * @param string $key * * @return void */ public function delete($key) { $this->store->delete($key); $this->cache->forget("store.{$key}"); }
/** * @param $name * @param $arguments * @return mixed */ public function __call($name, $arguments) { $result = call_user_func_array([$this->theme, $name], $arguments); $this->cache->forget('theme'); return $result; }
/** * @param Topic $topic * @param Forum $forum */ public function moveTopicToForum(Topic $topic, Forum $forum) { $this->cache->forget('forums.index_tree'); $this->cache->forget('forums.all'); return $this->decoratedRepository->moveTopicToForum($topic, $forum); }
/** * {@inheritdoc} */ public function deleteItem($key) { $this->validateKey($key); return $this->repository->forget($key); }
/** * Clear the hits and lockout for the given key. * * @param string $key * @return void */ public function clear($key) { $this->cache->forget($key); $this->cache->forget($key . ':lockout'); }
/** * Forget a value for a given key * @param $key */ public function cacheForget($key) { $this->cache->forget($this->cachePrefix($key)); }
/** * {@inheritDoc} */ public function destroy($sessionId) { return $this->cache->forget($sessionId); }
/** * Flush our cache of the user's repos. * * @param \StyleCI\StyleCI\Models\User $user * * @return void */ public function flush(User $user) { $this->cache->forget($user->id . 'repos'); }
/** * Forget the cached permissions. */ public function forgetCachedPermissions() { $this->cache->forget($this->cacheKey); }
/** * Reset the attempts counter. * * @author Andrea Marco Sartori * @return void */ public function resetAttempts() { $this->cache->forget($this->key); }
/** * Flush the cache so that the formatter components are regenerated. */ public function flush() { $this->cache->forget('flarum.formatter.parser'); $this->cache->forget('flarum.formatter.renderer'); }
/** * Remove an item from the cache. * * @param string $key * @return bool */ public function forget($key) { return $this->cache->forget($key); }