Skip to content

Commit 67ec47e

Browse files
committed
Fix project list cache not clearing automatically
The cache should clear after a project is created, updated or deleted in the CLI. Note the cache also expires after 10 minutes by default.
1 parent f45a53e commit 67ec47e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/Service/Api.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,7 @@ private function matchesVendorFilter($filters, BasicProjectInfo $project)
662662
*/
663663
public function getMyProjects($refresh = null)
664664
{
665-
$new = $this->config->get('api.centralized_permissions') && $this->config->get('api.organizations');
666-
$vendorFilter = $this->config->getWithDefault('api.vendor_filter', null);
667-
$cacheKey = sprintf('%s:my-projects%s:%s', $this->config->getSessionId(), $new ? ':new' : '', is_array($vendorFilter) ? implode(',', $vendorFilter) : (string) $vendorFilter);
665+
$cacheKey = $this->myProjectsCacheKey();
668666
$cached = $this->cache->fetch($cacheKey);
669667

670668
if ($refresh === false && !$cached) {
@@ -1010,12 +1008,23 @@ public function clearEnvironmentsCache($projectId)
10101008
}
10111009

10121010
/**
1013-
* Clear the projects cache.
1011+
* Calculates a cache key for the projects list.
1012+
*
1013+
* @return string
1014+
*/
1015+
private function myProjectsCacheKey()
1016+
{
1017+
$new = $this->config->get('api.centralized_permissions') && $this->config->get('api.organizations');
1018+
$vendorFilter = $this->config->getWithDefault('api.vendor_filter', null);
1019+
return sprintf('%s:my-projects%s:%s', $this->config->getSessionId(), $new ? ':new' : '', is_array($vendorFilter) ? implode(',', $vendorFilter) : (string) $vendorFilter);
1020+
}
1021+
1022+
/**
1023+
* Clears the projects cache.
10141024
*/
10151025
public function clearProjectsCache()
10161026
{
1017-
$this->cache->delete(sprintf('%s:project-stubs', $this->config->getSessionId()));
1018-
$this->cache->delete(sprintf('%s:my-account', $this->config->getSessionId()));
1027+
$this->cache->delete($this->myProjectsCacheKey());
10191028
}
10201029

10211030
/**

0 commit comments

Comments
 (0)