mirror of
https://github.com/nextcloud/server.git
synced 2026-04-23 07:08:34 -04:00
cache versioning enabled status
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
eb6e6e3a85
commit
a1ca901e58
1 changed files with 16 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue