Esempio n. 1
0
 /**
  * @param Repository $repository
  * @throws \Exception
  */
 private function setCacheRepository(Repository $repository)
 {
     if (!$repository->getStore() instanceof TaggableStore) {
         throw new \Exception('Cache driver must be extended from Illuminate\\Cache\\TaggableStore ');
     }
     $this->cache = $repository;
 }
 /**
  * @param Repository $repository
  *
  * @throws CacheTagsNotSupported
  * @return bool
  */
 public function isSatisfiedBy(Repository $repository)
 {
     if (!method_exists($repository->getStore(), 'tags')) {
         throw new CacheTagsNotSupported('Cache tags are necessary to use this kind of caching. Consider using a different caching method');
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Detect as best we can whether tags are supported with this repository & store,
  * and save our result on the $supportsTags flag.
  *
  * @return void
  */
 protected function determineTagSupport()
 {
     // Laravel >= 5.1.28
     if (method_exists($this->cache, 'tags')) {
         try {
             // Attempt the repository tags command, which throws exceptions when unsupported
             $this->cache->tags($this->tag);
             $this->supportsTags = true;
         } catch (BadMethodCallException $ex) {
             $this->supportsTags = false;
         }
     } else {
         // Laravel <= 5.1.27
         if (method_exists($this->cache, 'getStore')) {
             // Check for the tags function directly on the store
             $this->supportsTags = method_exists($this->cache->getStore(), 'tags');
         } else {
             // Must be using custom cache repository without getStore(), and all bets are off,
             // or we are mocking the cache contract (in testing), which will not create a getStore method
             $this->supportsTags = false;
         }
     }
 }
 /**
  * Make a new cache throttler instance.
  *
  * @param \GrahamCampbell\Throttle\Data $data
  *
  * @return \GrahamCampbell\Throttle\Throttlers\CacheThrottler
  */
 public function make(Data $data)
 {
     return new CacheThrottler($this->cache->getStore(), $data->getKey(), $data->getLimit(), $data->getTime());
 }