diff options
author | Robin Appelman <robin@icewind.nl> | 2021-10-19 15:03:22 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-10-26 14:45:59 +0200 |
commit | ce243798f68b0243e38a610cb7d3686f051cf978 (patch) | |
tree | ed4d1820db1be62968ff8a503e77b19d0c2ad3a3 /apps | |
parent | 759f2daf3854521e053411e3c80b4430f1627bfc (diff) | |
download | nextcloud-server-ce243798f68b0243e38a610cb7d3686f051cf978.tar.gz nextcloud-server-ce243798f68b0243e38a610cb7d3686f051cf978.zip |
cache versioning enabled status
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 64da89c12f2..df13603de23 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -52,6 +52,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; @@ -76,12 +78,19 @@ 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); $this->objectCache = new CappedMemoryCache(); $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 +730,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; } |