Skip to content

35820 - Do not persist remote file metadata cache #37653

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

Draft
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
40 changes: 2 additions & 38 deletions app/code/Magento/RemoteStorage/Driver/Adapter/Cache/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function purgeQueue(): void
{
foreach ($this->cachePathPurgeQueue as $path) {
unset($this->cacheData[$path]);
$this->cacheAdapter->remove($this->prefix . $path);
}
}

Expand All @@ -83,14 +82,6 @@ public function purgeQueue(): void
public function updateMetadata(string $path, array $objectMetadata, bool $persist = false): void
{
$this->cacheData[$path] = array_merge($this->pathUtil->pathInfo($path), $objectMetadata);
if ($persist) {
$this->cacheAdapter->save(
$this->serializer->serialize([$path => $this->cacheData[$path]]),
$this->prefix . $path,
[self::CACHE_TAG]
);
}

$this->ensureParentDirectories($path);
}

Expand All @@ -100,11 +91,6 @@ public function updateMetadata(string $path, array $objectMetadata, bool $persis
public function storeFileNotExists(string $path): void
{
$this->cacheData[$path] = false;
$this->cacheAdapter->save(
$this->serializer->serialize([$path => $this->cacheData[$path]]),
$this->prefix . $path,
[self::CACHE_TAG]
);
}

/**
Expand All @@ -113,13 +99,7 @@ public function storeFileNotExists(string $path): void
public function exists(string $path): ?bool
{
if (!isset($this->cacheData[$path])) {
$fileMeta = $this->cacheAdapter->load($this->prefix . $path);

if ($fileMeta === false) {
return null;
}

$this->setFromStorage($fileMeta);
return null;
}

return array_key_exists($path, $this->cacheData) ? $this->cacheData[$path] !== false : null;
Expand All @@ -137,11 +117,6 @@ public function moveFile(string $path, string $newpath): void
$object['path'] = $newpath;
$object = array_merge($object, $this->pathUtil->pathInfo($newpath));
$this->cacheData[$newpath] = $object;
$this->cacheAdapter->save(
$this->serializer->serialize([$newpath => $this->cacheData[$newpath]]),
$this->prefix . $newpath,
[self::CACHE_TAG]
);
$this->purgeQueue();
}
}
Expand Down Expand Up @@ -190,17 +165,7 @@ public function getMetadata(string $path): ?array
if (isset($this->cacheData[$path]['type'])) {
return $this->cacheData[$path];
} else {
$meta = $this->cacheAdapter->load($this->prefix . $path);
if (!$meta) {
return null;
}
$meta = $this->serializer->unserialize($meta);

if (empty($meta[$path])) {
return null;
}
$this->cacheData[$path] = $meta[$path];
return $this->cacheData[$path];
return null;
}
}

Expand All @@ -210,7 +175,6 @@ public function getMetadata(string $path): ?array
public function flushCache(): void
{
$this->cacheData = [];
$this->cacheAdapter->clean([self::CACHE_TAG]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function fileExists(string $path): bool
$this->cache->storeFileNotExists($path);
} else {
$cacheEntry = is_array($exists) ? $exists : ['path' => $path];
$this->cache->updateMetadata($path, $cacheEntry, true);
$this->cache->updateMetadata($path, $cacheEntry, false);
}

return $exists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getMetadata(string $path): array
if (isset($extraMetadata['Metadata']['image-width']) && isset($extraMetadata['Metadata']['image-height'])) {
$data['extra'] = $extraMetadata['Metadata'];
}
$this->cache->updateMetadata($path, $data, true);
$this->cache->updateMetadata($path, $data, false);
return $data;
}

Expand Down