Skip to content

Commit

Permalink
PHP: Defined rules to cache QGIS Server metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jan 30, 2025
1 parent d4be51c commit f1f6884
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lizmap/modules/lizmap/lib/Request/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lizmap/var/config/profiles.ini.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f1f6884

Please sign in to comment.