/** * @param RepositoryEventBase $event */ public function handle(RepositoryEventBase $event) { try { $cleanEnabled = config('repository.cache.clean.enabled', true); if ($cleanEnabled) { $this->repository = $event->getRepository(); $this->model = $event->getModel(); $this->action = $event->getAction(); if (config("repository.cache.clean.on.{$this->action}", true)) { $cacheKeys = CacheKeys::getKeys(get_class($this->repository)); if (is_array($cacheKeys)) { foreach ($cacheKeys as $key) { $this->cache->forget($key); } } } } } catch (\Exception $e) { logger()->error($e->getMessage()); } }
/** * Get Cache key for the method. * * @param $method * @param $args * * @return string */ public function getCacheKey($method, $args = null) { $request = app('Illuminate\\Http\\Request'); $args = serialize($args); $key = sprintf('%s@%s-%s', get_called_class(), $method, md5($args . $request->fullUrl())); CacheKeys::putKey(get_called_class(), $key); return $key; }