diff options
author | Robin Appelman <robin@icewind.nl> | 2021-10-19 15:03:22 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-10-22 12:34:31 +0000 |
commit | e62390045aa6289195e34fd6ea6d96d46e7ab33f (patch) | |
tree | 537d94e1222dabf7f2216641a8479cbbcb87408b /apps/files_external | |
parent | da4712b62c3625f43110d4ffbb8524a7b2b318ab (diff) | |
download | nextcloud-server-e62390045aa6289195e34fd6ea6d96d46e7ab33f.tar.gz nextcloud-server-e62390045aa6289195e34fd6ea6d96d46e7ab33f.zip |
cache versioning enabled status
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index cb5fe134e6f..827fd63d1d6 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -51,6 +51,8 @@ use OC\Files\ObjectStore\S3ObjectTrait; use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\IMimeTypeDetector; +use OCP\ICacheFactory; +use OCP\IMemcache; class AmazonS3 extends \OC\Files\Storage\Common { use S3ConnectionTrait; @@ -75,6 +77,9 @@ class AmazonS3 extends \OC\Files\Storage\Common { /** @var bool|null */ private $versioningEnabled = null; + /** @var IMemcache */ + private $memCache; + public function __construct($parameters) { parent::__construct($parameters); $this->parseParams($parameters); @@ -82,6 +87,9 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->directoryCache = new CappedMemoryCache(); $this->filesCache = new CappedMemoryCache(); $this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class); + /** @var ICacheFactory $cacheFactory */ + $cacheFactory = \OC::$server->get(ICacheFactory::class); + $this->memCache = $cacheFactory->createLocal('s3-external'); } /** @@ -721,8 +729,14 @@ class AmazonS3 extends \OC\Files\Storage\Common { public function versioningEnabled(): bool { if ($this->versioningEnabled === null) { - $result = $this->getConnection()->getBucketVersioning(['Bucket' => $this->getBucket()]); - $this->versioningEnabled = $result->get('Status') === 'Enabled'; + $cached = $this->memCache->get('versioning-enabled::' . $this->getBucket()); + if ($cached === null) { + $result = $this->getConnection()->getBucketVersioning(['Bucket' => $this->getBucket()]); + $this->versioningEnabled = $result->get('Status') === 'Enabled'; + $this->memCache->set('versioning-enabled::' . $this->getBucket(), $this->versioningEnabled, 60); + } else { + $this->versioningEnabled = $cached; + } } return $this->versioningEnabled; } |