Skip to content
Merged
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
fix(caching): Avoid checking existence before fetching
The cache might expire between checking for key existence and fetching
the value. In this rare case the code continues with a null value when
it doesn't expect one.

Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst authored and szaimen committed Jun 12, 2023
commit b8c61b3515ef406c4feafc851f12262e417ba157
5 changes: 3 additions & 2 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ private function normalizePath(string $path) {
* @throws \OCP\Files\StorageNotAvailableException
*/
private function fetchObject(string $path) {
if ($this->objectCache->hasKey($path)) {
$cached = $this->objectCache->get($path);
if ($cached !== null) {
// might be "false" if object did not exist from last check
return $this->objectCache->get($path);
return $cached;
}
try {
$object = $this->getContainer()->getObject($path);
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ protected function testRemote(): bool {

private function testRemoteUrl(string $url): bool {
$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
if ($cache->hasKey($url)) {
return (bool)$cache->get($url);
$cached = $cache->get($url);
if ($cached !== null) {
return (bool)$cached;
}

$client = $this->httpClient->newClient();
Expand Down
5 changes: 3 additions & 2 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ private function verifyMountPoint(
$this->eventDispatcher->dispatchTyped($event);
$parent = $event->getParent();

if ($folderExistCache->hasKey($parent)) {
$parentExists = $folderExistCache->get($parent);
$cached = $folderExistCache->get($parent);
if ($cached) {
$parentExists = $cached;
} else {
$parentExists = $this->recipientView->is_dir($parent);
$folderExistCache->set($parent, $parentExists);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,9 @@ private function parseAccountData(IUser $user, $data): Account {
}

public function getAccount(IUser $user): IAccount {
if ($this->internalCache->hasKey($user->getUID())) {
return $this->internalCache->get($user->getUID());
$cached = $this->internalCache->get($user->getUID());
if ($cached !== null) {
return $cached;
}
$account = $this->parseAccountData($user, $this->getUser($user));
$this->internalCache->set($user->getUID(), $account);
Expand Down