Beispiel #1
0
 /**
  * Gets Tag objects from cache or DB
  * @param CacheHandlerInterface $cacheHandler
  * @param TagRepositoryInterface $tagRepo
  * @return array
  */
 public function getTagsForUser(CacheHandlerInterface $cacheHandler, TagRepositoryInterface $tagRepo)
 {
     // Check to see if there is a cache item
     $tags = $cacheHandler->get(CacheHandlerInterface::TAGS);
     // No tags found in cache, check DB, cache them, and return them
     if (!$tags) {
         $tags = $tagRepo->all(Auth::user());
         $tagNames = [];
         foreach ($tags as $tag) {
             $tagNames[] = $tag->name;
         }
         $cacheHandler->set(CacheHandlerInterface::TAGS, $tagNames);
         return $tagNames;
     }
     return $tags;
 }
Beispiel #2
0
 /**
  * Get items for display
  *
  * @param Request $request
  * @param CacheHandlerInterface $cacheHandler
  * @param ItemRepositoryInterface $itemRepo
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getAll(Request $request, CacheHandlerInterface $cacheHandler, ItemRepositoryInterface $itemRepo)
 {
     $pageRequested = $request->input('page');
     $isMainPage = (is_null($pageRequested) or $pageRequested === 1);
     if ($isMainPage) {
         // Load from cache if available
         $items = $cacheHandler->get(CacheHandlerInterface::MAINPAGE);
     } else {
         $items = $itemRepo->getItemsPaginated(20, Auth::user());
     }
     // Main page data not available in cache
     if (!$items) {
         // Get paginated items for user
         $items = $itemRepo->getItemsPaginated(20, Auth::user());
         // Save in cache for next request
         $cacheHandler->set(CacheHandlerInterface::MAINPAGE, $items);
     }
     $title = "List";
     return view('all', ['items' => $items, 'title' => $title]);
 }