summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-04-22 12:50:42 +0200
committerRobin Appelman <robin@icewind.nl>2022-04-22 13:02:30 +0200
commit674c0bec2cbe131e13c17ac1de4f47007f2b2821 (patch)
treed7464ead6fa074d244d845a84b3116ae73c7be58 /lib
parent9a76f06ecadf05ef1d26bd735df1bea0dfb15d59 (diff)
downloadnextcloud-server-674c0bec2cbe131e13c17ac1de4f47007f2b2821.tar.gz
nextcloud-server-674c0bec2cbe131e13c17ac1de4f47007f2b2821.zip
cache display names in local memory before external memcache
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/User/DisplayNameCache.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/private/User/DisplayNameCache.php b/lib/private/User/DisplayNameCache.php
index ed0c723ef37..22a79863e49 100644
--- a/lib/private/User/DisplayNameCache.php
+++ b/lib/private/User/DisplayNameCache.php
@@ -38,17 +38,22 @@ use OCP\User\Events\UserChangedEvent;
* outdated.
*/
class DisplayNameCache implements IEventListener {
- private ICache $internalCache;
+ private array $cache = [];
+ private ICache $memCache;
private IUserManager $userManager;
public function __construct(ICacheFactory $cacheFactory, IUserManager $userManager) {
- $this->internalCache = $cacheFactory->createDistributed('displayNameMappingCache');
+ $this->memCache = $cacheFactory->createDistributed('displayNameMappingCache');
$this->userManager = $userManager;
}
public function getDisplayName(string $userId) {
- $displayName = $this->internalCache->get($userId);
+ if (isset($this->cache[$userId])) {
+ return $this->cache[$userId];
+ }
+ $displayName = $this->memCache->get($userId);
if ($displayName) {
+ $this->cache[$userId] = $displayName;
return $displayName;
}
@@ -58,20 +63,23 @@ class DisplayNameCache implements IEventListener {
} else {
$displayName = $userId;
}
- $this->internalCache->set($userId, $displayName, 60 * 10); // 10 minutes
+ $this->cache[$userId] = $displayName;
+ $this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes
return $displayName;
}
public function clear(): void {
- $this->internalCache->clear();
+ $this->cache = [];
+ $this->memCache->clear();
}
public function handle(Event $event): void {
if ($event instanceof UserChangedEvent && $event->getFeature() === 'displayName') {
$userId = $event->getUser()->getUID();
$newDisplayName = $event->getValue();
- $this->internalCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
+ $this->cache[$userId] = $newDisplayName;
+ $this->memCache->set($userId, $newDisplayName, 60 * 10); // 10 minutes
}
}
}