Add a cache plugin to cache responses locally.

@param \Psr\Cache\CacheItemPoolInterface $cachePool
@param array                             $config

@return void
15933
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
    {
        $this->setCachePlugin($cachePool, $config['generator'] ?? null, $config['lifetime'] ?? null);

        $this->setPropertyValue('httpClientModified', true);
    }
753589
protected function addCacheDirectory(ContainerInterface $container, SerializerBuilder $builder): void
    {
        $config = $container->get('config');
        $libraryConfig = $config[ConfigKey::PROJECT][ConfigKey::API_CLIENT] ?? [];
        $cacheDir = (string) ($libraryConfig[ConfigKey::CACHE_DIR] ?? '');

        if ($cacheDir !== '') {
            $builder->setCacheDir($cacheDir);
        }
    }
1234003
private function createFileCache($subClassName, array $cacheConfig, ContainerBuilder $container)
    {
        $cacheDir = $this->getFileCacheDir($cacheConfig, $container);
        Utility::appendParameter('dirs', 'metadata_cache_dir', $cacheDir, $container);

        return new Definition(
            Utility::getLibraryClass($subClassName),
            [$cacheDir]
        );
    }
59839
private function _setCacheStrategy(string $cacheStrategy) : void
    {
        $cacheStrategyClassName = self::CACHE_STRATEGIES[$cacheStrategy] ?? $cacheStrategy;

        if (!InterfaceHelper::implementsInterface($cacheStrategyClassName, CacheStrategy::class))
        {
            throw new UnknownCacheStrategyException($cacheStrategyClassName, \array_values(self::CACHE_STRATEGIES));
        }

        $this->_cacheStrategy = new $cacheStrategyClassName($this->_storage);
    }
1349647
protected function getCacheRepository(array $config): CacheRepository
    {
        $connection = $config['connections']['cache'] ?? null;

        return $this->app->make('cache')->driver($connection);
    }
318070
public function loadCachedConfig(array &$config)
    {
        $cacheFilePath = $this->config->getCacheFile();

        if (!file_exists($cacheFilePath)) {
            return false;
        }

        $cachedConfig = include $cacheFilePath;

        if (!is_array($cachedConfig)) {
            return false;
        }

        if (!isset($config['routes'])) {
            $config['routes'] = array();
        }

        $this->merger->merge($cachedConfig, $config['routes']);

        return true;
    }
842391
public static function get(CacheItemPoolInterface $pool, array $config)
    {
        if ($config['use_tagging']) {
            $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), ['validation']);
        }

        if (!empty($config['prefix'])) {
            $pool = new PrefixedCachePool($pool, $config['prefix']);
        }

        return new SymfonyValidatorBridge($pool);
    }
1301425
private function newMemcacheClient($name, array $config, ContainerBuilder $container)
    {
        // Check if the Memcache extension is loaded
        if (!extension_loaded('memcache')) {
            throw new \LogicException('Memcache extension is not loaded! To configure pools it MUST be loaded!');
        }

        $memcache = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache');
        $memcache->addArgument(new Parameter('kernel.debug'));

        // Add servers to the memcache pool
        foreach ($config['servers'] as $s) {
            $server = array(
                $s['host'],
                $s['tcp_port'],
                $s['udp_port'],
                $s['persistent'],
                $s['weight'],
                $s['timeout'],
                $s['retry_interval']
            );
            if ($s['host']) {
                $memcache->addMethodCall('addServer', $server);
            }
        }
        
        $memcache->addArgument($config['options']);

        $options = array();
        // Make sure that config values are human readable
        foreach ($config['options'] as $key => $value) {
            $options[$key] = var_export($value, true);
        }

        // Add the service to the container
        $serviceName = sprintf('memcache.%s', $name);
        $container->setDefinition($serviceName, $memcache);
        // Add the service to the data collector
        if ($container->hasDefinition('memcache.data_collector')) {
            $definition = $container->getDefinition('memcache.data_collector');
            $definition->addMethodCall('addClient', array($name, $options, new Reference($serviceName)));
        }
    }
1185512
protected function setUpSpecificConfigurations(Configuration $config)
    {
        $config->setQueryCacheImpl($this->getQueryCacheDriver());
        $config->setResultCacheImpl($this->getResultCacheDriver());
        $config->setHydrationCacheImpl($this->getHydratorCacheDriver());

        $config->setNamingStrategy($this->getNamingStrategy());
        $config->setQuoteStrategy($this->getQuoteStrategy());

        if ($this->getSecondLevelCacheConfiguration() !== null) {
            $config->setSecondLevelCacheEnabled(true);
            $config->setSecondLevelCacheConfiguration($this->getSecondLevelCacheConfiguration());
        }

        $config->setSQLLogger($this->getSQLLogger());
        $config->setCustomStringFunctions($this->getCustomStringFunctions());
        $config->setCustomNumericFunctions($this->getCustomNumericFunctions());
        $config->setCustomDatetimeFunctions($this->getCustomDateTimeFunctions());

        foreach ($this->getCustomFilters() as $name => $filterClass) {
            $config->addFilter($name, $filterClass);
        }
    }
145641
private static function createConfiguration(array $config, ContainerInterface $container = null)
    {
        $cache = $config['cache'];

        if ($container && is_string($config['cache']) && $container->has($config['cache'])) {
            $cache = $container->get($config['cache']);
        }

        return Setup::createConfiguration($config['debug'], $config['proxy_dir'], $cache);
    }
72048
protected function _initialize(AnConfig $config)
    {
        $config->append(array(
            'cache' => true,
            'cache_key' => (string) $this->getIdentifier(),
        ));

        parent::_initialize($config);
    }
633219
public function cache($key, $config = 'default')
    {
        if ($this->_type !== 'select' && $this->_type !== null) {
            throw new RuntimeException('You cannot cache the results of non-select queries.');
        }

        return $this->_cache($key, $config);
    }
666661
public function load(array $config, ContainerBuilder $container)
    {
        $config = $this->processConfiguration(new Configuration(), $config);

        $provider = $config['provider'];
        $container->setParameter(
            'openclassrooms.cache.default_lifetime',
            $config['default_lifetime']
        );

        $container->setParameter(
            'openclassrooms.cache.cache_provider_type',
            key($provider)
        );

        switch (key($provider)) {
            case CacheProviderType::REDIS:
                $providerConfig = $provider[CacheProviderType::REDIS];
                $container->setParameter('openclassrooms.cache.provider_host', $providerConfig['host']);
                $container->setParameter('openclassrooms.cache.provider_port', $providerConfig['port']);
                $container->setParameter('openclassrooms.cache.provider_timeout', $providerConfig['timeout']);
                break;
            default;
                break;
        }

        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
        $loader->load('services.xml');
    }
1264134
public function addAdapter($name, CacheItemPoolInterface $adapter, $default = false)
    {
        if (false === is_string($name)) {
            throw CacheException::adapterNameNotString($name);
        }

        if (true === array_key_exists($name, $this->adapters)) {
            throw CacheException::adapterAlreadyExists($name);
        }

        $this->adapters[$name] = $adapter;

        if (true === $default) {
            $this->setDefaultAdapterName($name);
        }
    }
1256251
protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
    {
        $registry = new Definition(QueueRegistry::class);
        $container->setDefinition('alchemy_queues.registry', $registry);

        $queueConfigurations = $mergedConfig['queues'];

        if ($mergedConfig['logger'] != '') {
            $registry->addMethodCall('setLogger', [ new Reference($mergedConfig['logger']) ]);
        }

        foreach ($queueConfigurations as $name => $configuration) {
            $targetRegistry = $registry;

            if (isset($configuration['registry'])) {
                $targetRegistry = $container->getDefinition($configuration['registry']);
            }

            $targetRegistry->addMethodCall('bindConfiguration', [ $name, $configuration ]);
        }
    }
1014920
public function addCache(CacheInterface $cache, $priority = 0)
    {
        $this->caches[spl_object_hash($cache)] = array(
            'cache' => $cache,
            'priority' => $priority
        );

        $this->sortedCaches = null;
    }
1293494
public static function get(CacheItemPoolInterface $pool, array $config)
    {
        if ($config['use_tagging']) {
            $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), ['session']);
        }

        return new Psr6SessionHandler($pool, $config);
    }