diff --git a/lizmap/modules/lizmap/lib/Request/Proxy.php b/lizmap/modules/lizmap/lib/Request/Proxy.php index d1da1f7984..22bb8bdfa3 100644 --- a/lizmap/modules/lizmap/lib/Request/Proxy.php +++ b/lizmap/modules/lizmap/lib/Request/Proxy.php @@ -13,8 +13,11 @@ namespace Lizmap\Request; use GuzzleHttp\Client; +use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; +use Kevinrob\GuzzleCache\CacheMiddleware; +use Kevinrob\GuzzleCache\Strategy; use Lizmap\App; use Psr\Http\Message\ResponseInterface; @@ -385,10 +388,24 @@ protected static function sendRequest($url, $options) $options['headers']['Referer'] = $options['referer']; } + // Create request cache strategy + $strategy = new Strategy\Delegate\DelegatingCacheStrategy($defaultStrategy = new Strategy\NullCacheStrategy()); + $lizmapServices = self::getServices(); + $qgisServerUrl = $lizmapServices->getUrlLizmapQgisServerMetadata(); + $strategy->registerRequestMatcher( + new QgisServerMetadataRequestMatcher($qgisServerUrl), + new Strategy\GreedyCacheStrategy(new RequestCacheStorage('requests')) // default TTL to 60 seconds + ); + // Create request stack handler + $stack = HandlerStack::create(); + $stack->push(new CacheMiddleware($strategy)); + // Create Client $client = new Client(array( // You can set any number of default request options. 'timeout' => max(10.0, floatval(ini_get('max_execution_time')) - 5.0), + // Set stack handler + 'handler' => $stack, )); // Create request diff --git a/lizmap/var/config/profiles.ini.php.dist b/lizmap/var/config/profiles.ini.php.dist index b4d55dd37e..5715dc73e3 100644 --- a/lizmap/var/config/profiles.ini.php.dist +++ b/lizmap/var/config/profiles.ini.php.dist @@ -90,7 +90,7 @@ searchGroupBaseDN="" ; name of the default profil to use for cache default=lizmap - +; the other jcache could be : qgisprojects, acl2db, tiles, requests [jcache:lizmap] ; disable or enable cache for this profile