app/Customize/Service/Cache/UserDataCache.php line 28

Open in your IDE?
  1. <?php
  2. namespace Customize\Service\Cache;
  3. use Customize\Common\Constants;
  4. use Eccube\Entity\ProductClass;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  7. use Customize\Controller\Trait\KrakiFileTrait;
  8. use Eccube\Common\EccubeConfig;
  9. class UserDataCache
  10. {
  11.     use KrakiFileTrait;
  12.     private $entityManager;
  13.     public function __construct(EntityManagerInterface $entityManagerEccubeConfig $eccubeConfig)
  14.     {
  15.         $this->entityManager $entityManager;
  16.         $this->getSettingFile($eccubeConfig);
  17.     }
  18.     public function getSecurePackProductClass()
  19.     {
  20.         $cache = new FilesystemAdapter(Constants::USER_DATA_CACHE60*60*24); // time to auto clear cache (1 day)
  21.         $cacheItem $cache->getItem(Constants::SECURE_PACK_CACHE_KEY); // this text is name of cache item's key
  22.         if (!$cacheItem->isHit()) {            
  23.             $productClass $this->entityManager->getRepository(ProductClass::class)->findOneBy([
  24.                 'code' => $this->settings["secure_pack"]["product_code"]
  25.             ]);
  26.             $cacheItem->set($productClass);
  27.             $cache->save($cacheItem);
  28.         }
  29.         return $cacheItem->get();
  30.     }
  31. }