/** * Display a listing of the resource. * * @param \App\Http\Requests\FilterArticlesRequest $request * @param int|null $id * @return \Illuminate\Http\Response */ public function index(FilterArticlesRequest $request, $id = null) { $query = $id ? Tag::findOrFail($id)->articles() : new Article(); // If you are relying on 'file' or 'database' cache, cacheTags() methods is not available $query = taggable() ? $query->with('comments', 'author', 'tags', 'attachments')->remember(5)->cacheTags('articles') : $query->with('comments', 'author', 'tags', 'solution', 'attachments')->remember(5); $articles = $this->filter($request, $query)->paginate(10); return view('articles.index', compact('articles')); }
/** * Handle the event. * * @param \App\Events\ModelChanged $event */ public function handle(ModelChanged $event) { if (!taggable()) { // Remove all cache store return \Cache::flush(); } // Remove only cache that has the given tag(s) return \Cache::tags($event->cacheTags)->flush(); }
/** * Constructor */ public function __construct() { if (!is_api_request()) { $this->setSharedVariables(); } $this->cache = app('cache'); if ((new \ReflectionClass($this))->implementsInterface(\App\Http\Controllers\Cacheable::class) and taggable()) { $this->cache = app('cache')->tags($this->cacheKeys()); } }