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

[BUGFIX] Use different cache keys for different bucket URLs #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 11 additions & 4 deletions Classes/Driver/AmazonS3Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class AmazonS3Driver extends AbstractHierarchicalFilesystemDriver implements Str
*/
protected FrontendInterface $requestCache;

/**
* To differentiate between multiple drivers
*/
protected string $cachePrefix = '';

/**
* Object permissions are cached here in subarrays like:
* $identifier => ['r' => bool, 'w' => bool]
Expand Down Expand Up @@ -1151,6 +1156,8 @@ protected function initializeClient()
$this->s3Client = new S3Client($configuration);
StreamWrapper::register($this->s3Client, $this->streamWrapperProtocol);
}

$this->cachePrefix = md5($configuration['endpoint']) . '-';
return $this;
}

Expand Down Expand Up @@ -1232,7 +1239,7 @@ protected function prefixExists(string $identifier): bool
protected function getMetaInfo($identifier): ?array
{
$this->normalizeIdentifier($identifier);
$cacheIdentifier = md5($identifier);
$cacheIdentifier = $this->cachePrefix . md5($identifier);
$metaInfo = $this->metaInfoCache->has($cacheIdentifier) ? $this->metaInfoCache->get($cacheIdentifier) : false;
if ($metaInfo) {
return $metaInfo;
Expand Down Expand Up @@ -1266,7 +1273,7 @@ protected function getMetaInfo($identifier): ?array
*/
protected function getCachedResponse($function, $parameter)
{
$cacheIdentifier = md5($function) . '-' . md5(serialize($parameter));
$cacheIdentifier = $this->cachePrefix . md5($function) . '-' . md5(serialize($parameter));

if ($this->requestCache->has($cacheIdentifier)) {
$response = $this->requestCache->get($cacheIdentifier);
Expand All @@ -1289,7 +1296,7 @@ protected function getCachedResponse($function, $parameter)
protected function flushMetaInfoCache($identifier): void
{
$this->normalizeIdentifier($identifier);
$cacheIdentifier = md5($identifier);
$cacheIdentifier = $this->cachePrefix . md5($identifier);
if ($this->metaInfoCache->has($cacheIdentifier)) {
$this->metaInfoCache->remove($cacheIdentifier);
}
Expand Down Expand Up @@ -1533,7 +1540,7 @@ protected function getListObjects($identifier, $overrideArgs = [])
foreach ($result['Contents'] as $content) {
$fileIdentifier = $content['Key'];
$this->normalizeIdentifier($fileIdentifier);
$cacheIdentifier = md5($fileIdentifier);
$cacheIdentifier = $this->cachePrefix . md5($fileIdentifier);
if (!$this->metaInfoCache->has($cacheIdentifier) || !$this->metaInfoCache->get($cacheIdentifier)) {
$this->metaInfoCache->set($cacheIdentifier, $metaInfoDownloadAdapter->getMetaInfoFromResponse($this, $fileIdentifier, $content));
}
Expand Down
Loading