src/CachedProductRepository.php
public function getProducts()
    {
        $cacheKey = "products";
        if ($this->cache->hasItem($cacheKey)) {

            // return from cache
            $cacheItem = $this->cache->getItem($cacheKey);
            $cachedProducts = $cacheItem->get();
            return $cachedProducts;
        }

        $products = $this->productRepository->getProducts();

        // save to cache
        $cacheItem = $this->cache->getItem($cacheKey);
        $cacheItem->set($products);

        return $products;
    }
public function getProducts()
    {
        $cacheKey = "products";
        if ($this->cache->hasItem($cacheKey)) {

            // return from cache
            $cacheItem = $this->cache->getItem($cacheKey);
            $cachedProducts = $cacheItem->get();
            return $cachedProducts;
        }

        $products = $this->productRepository->getProducts();

        // save to cache
        $cacheItem = $this->cache->getItem($cacheKey);
        $cacheItem->set($products);

        return $products;
    }
Get all products

@return Product[]

@throws RepositoryException If fetching the products failed