Skip to content

Commit

Permalink
Merge pull request #6688 from Quetzacoalt91/cache-on-guzzle-requests
Browse files Browse the repository at this point in the history
Enable cache on guzzle requests
  • Loading branch information
mickaelandrieu committed Oct 17, 2016
2 parents 8fd0a53 + 6c06898 commit 83a16f3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/config/config.yml
Expand Up @@ -99,6 +99,9 @@ swiftmailer:
csa_guzzle:
profiler:
enabled: "%kernel.debug%"
cache:
enabled: true
adapter: guzzle.cache
clients:
addons_api:
config: # you can specify the options as in http://docs.guzzlephp.org/en/latest/quickstart.html#creating-a-client
Expand All @@ -110,4 +113,5 @@ csa_guzzle:
prestashop:
addons:
api_client:
ttl: 7200 # 2h
verify_ssl: ~ # true by default, declaring "addons.api_client.verify_ssl" parameter overrides its usage
5 changes: 5 additions & 0 deletions app/config/config_dev.yml
Expand Up @@ -44,3 +44,8 @@ monolog:

#swiftmailer:
# delivery_address: me@example.com

prestashop:
addons:
api_client:
ttl: 300 # 5min
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -7,6 +7,7 @@
"symfony/symfony": "~2.8.6",
"defuse/php-encryption": "~2.0.1",
"doctrine/dbal": "~2.5.3",
"doctrine/cache": "~1.6|~1.5",
"doctrine/common": "~2.5.3",
"doctrine/orm": "~2.5.3",
"ext-intl": "*",
Expand Down
Expand Up @@ -41,6 +41,9 @@ public function getConfigTreeBuilder()
->children()
->arrayNode('api_client')
->children()
->integerNode('ttl')
->defaultValue(0)
->end()
->booleanNode('verify_ssl')
->defaultTrue()
->end()
Expand Down
Expand Up @@ -55,6 +55,9 @@ public function load(array $configs, ContainerBuilder $container)
}

$container->setParameter('prestashop.addons.api_client.verify_ssl', $verifySsl);
if (!$container->hasParameter('prestashop.addons.api_client.ttl')) {
$container->setParameter('prestashop.addons.api_client.ttl', $config['addons']['api_client']['ttl']);
}

$this->addClassesToCompile(array(
$container->getDefinition('prestashop.router')->getClass(),
Expand Down
12 changes: 12 additions & 0 deletions src/PrestaShopBundle/Resources/config/services.yml
Expand Up @@ -6,6 +6,18 @@ services:
finder:
class: Symfony\Component\Finder\Finder
shared: false

guzzle.cache.provider:
class: Doctrine\Common\Cache\FilesystemCache
arguments:
- "%kernel.cache_dir%/guzzle"

guzzle.cache:
class: Csa\Bundle\GuzzleBundle\GuzzleHttp\Cache\DoctrineAdapter
arguments:
- "@guzzle.cache.provider"
- "%prestashop.addons.api_client.ttl%"
shared: false

main.warmer.cache_warmer:
class: PrestaShopBundle\Cache\CacheWarmer
Expand Down

0 comments on commit 83a16f3

Please sign in to comment.