Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Utilisation du cache handler de projet #95

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions cadastre/classes/lizmapCadastreRequest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ public function process_getcapabilities()

protected function getcapabilities()
{
$appContext = $this->appContext;
// Get cached session
$key = session_id() . '-' .
$this->project->getRepository()->getKey() . '-' .
$this->project->getKey() . '-' .
$this->param('service') . '-getcapabilities';
if (jAuth::isConnected()) {
$juser = jAuth::getUserSession();
// the cache should be unique between each user/service because the
// request content depends on rights of the user
$key = session_id() . '-' . $this->param('service');
$version = $this->param('version');
if ($version) {
$key .= '-' . $version;
}
if ($appContext->UserIsConnected()) {
$juser = $appContext->getUserSession();
$key .= '-' . $juser->login;
}
$key = sha1($key);
$key = 'getcapabilities-' . sha1($key);
$cached = false;

try {
$cached = jCache::get($key, 'qgisprojects');
$cached = $this->project->getCacheHandler()->getProjectRelatedDataCache($key);
} catch (Exception $e) {
// if qgisprojects profile does not exist, or if there is an
// other error about the cache, let's log it
jLog::logEx($e, 'error');
}
// invalid cache
if ($cached !== false && $cached['mtime'] < $this->project->getFileTime()) {
$cached = false;
}
// return cached data
if ($cached !== false) {
return (object) array(
Expand All @@ -53,38 +53,40 @@ protected function getcapabilities()
);
}

$querystring = $this->constructUrl();

// Get remote data
list($data, $mime, $code) = lizmapProxy::getRemoteData($querystring);
$response = $this->request();

// Retry if 500 error ( hackish, but QGIS Server segfault sometimes with cache issue )
if ($code == 500) {
// Get remote data
list($data, $mime, $code) = lizmapProxy::getRemoteData($querystring);
$response = $this->request();
}

if ($mime != 'text/json' && $mime != 'application/json') {
$code = 400;
$mime = 'application/json';
$data = json_encode((object) array(
'status' => 'fail',
'message' => 'Cadastre - Plugin non disponible',
));
if ($response->mime != 'text/json' && $response->mime != 'application/json') {
return (object) array(
'code' => 400,
'mime' => 'application/json',
'data' => json_encode((object) array(
'status' => 'fail',
'message' => 'Cadastre - Plugin non disponible',
)),
'cached' => false,
);
}

$cached = array(
'mtime' => $this->project->getFileTime(),
'code' => $code,
'mime' => $mime,
'data' => $data,
);
$cached = jCache::set($key, $cached, 3600, 'qgisprojects');
if ($response->code == 200) {
$cachedContent = array(
'code' => $response->code,
'mime' => $response->mime,
'data' => $response->data,
);
$cached = $this->project->getCacheHandler()->setProjectRelatedDataCache($key, $cachedContent, 3600);
}

return (object) array(
'code' => $code,
'mime' => $mime,
'data' => $data,
'code' => $response->code,
'mime' => $response->mime,
'data' => $response->data,
'cached' => $cached,
);
}
Expand Down