diff --git a/lib/private/Memcache/WithLocalCache.php b/lib/private/Memcache/WithLocalCache.php new file mode 100644 index 0000000000000..5b7ccc10e3966 --- /dev/null +++ b/lib/private/Memcache/WithLocalCache.php @@ -0,0 +1,54 @@ +inner = $inner; + $this->cached = new CappedMemoryCache($localCapacity); + } + + public function get($key) { + if (isset($this->cached[$key])) { + return $this->cached[$key]; + } else { + $value = $this->inner->get($key); + if (!is_null($value)) { + $this->cached[$key] = $value; + } + return $value; + } + } + + public function set($key, $value, $ttl = 0) { + $this->cached[$key] = $value; + return $this->inner->set($key, $value, $ttl); + } + + public function hasKey($key) { + return isset($this->cached[$key]) || $this->inner->hasKey($key); + } + + public function remove($key) { + unset($this->cached[$key]); + return $this->inner->remove($key); + } + + public function clear($prefix = '') { + $this->cached->clear(); + return $this->inner->clear($prefix); + } + + public static function isAvailable(): bool { + return false; + } +} diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 937d825ed777d..859ebd2a604a8 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -34,6 +34,7 @@ namespace OC\User; use OC\Hooks\PublicEmitter; +use OC\Memcache\WithLocalCache; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\HintException; @@ -104,7 +105,7 @@ public function __construct(IConfig $config, IEventDispatcher $eventDispatcher) { $this->config = $config; $this->dispatcher = $oldDispatcher; - $this->cache = $cacheFactory->createDistributed('user_backend_map'); + $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $cachedUsers = &$this->cachedUsers; $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { /** @var \OC\User\User $user */