Skip to content
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
42 changes: 23 additions & 19 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016-2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
Expand Down Expand Up @@ -32,10 +32,6 @@ class AmazonS3 extends Common {

private LoggerInterface $logger;

public function needsPartFile(): bool {
return false;
}

/** @var CappedMemoryCache<array|false> */
private CappedMemoryCache $objectCache;

Expand Down Expand Up @@ -77,6 +73,10 @@ private function isRoot(string $path): bool {
return $path === '.';
}

public function needsPartFile(): bool {
return false;
}

private function cleanKey(string $path): string {
if ($this->isRoot($path)) {
return '/';
Expand All @@ -90,24 +90,28 @@ private function clearCache(): void {
$this->filesCache = new CappedMemoryCache();
}

private function invalidateCache(string $key): void {
unset($this->objectCache[$key]);
$keys = array_keys($this->objectCache->getData());
$keyLength = strlen($key);
foreach ($keys as $existingKey) {
if (substr($existingKey, 0, $keyLength) === $key) {
unset($this->objectCache[$existingKey]);
}
private function invalidateCache(string $prefix): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private function invalidateCache(string $prefix): void {
/** @param non-empty-string $prefix */
private function invalidateCache(string $prefix): void {

if that should never happen

if ($prefix === '') {
return; // or throw InvalidArgumentException?
}
unset($this->filesCache[$key]);
$keys = array_keys($this->directoryCache->getData());
$keyLength = strlen($key);

$this->invalidateByPrefix($this->objectCache, $prefix);
$this->invalidateByPrefix($this->directoryCache, $prefix);

// FILES: exact match keys only (not hierarchical)
unset($this->filesCache[$prefix]);
}

private function invalidateByPrefix(CappedMemoryCache $cache, string $prefix): void {
$keys = array_keys($cache->getData());
$descendantPrefix = rtrim($prefix, '/') . '/';

foreach ($keys as $existingKey) {
if (substr($existingKey, 0, $keyLength) === $key) {
unset($this->directoryCache[$existingKey]);
// exact + normalized prefix matched keys
if ($existingKey === $prefix || str_starts_with($existingKey, $descendantPrefix)) {
unset($cache[$existingKey]);
}
}
unset($this->directoryCache[$key]);
}

private function headObject(string $key): array|false {
Expand Down
Loading