Skip to content
Prev Previous commit
Next Next commit
cache versioning enabled status
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Oct 26, 2021
commit ce243798f68b0243e38a610cb7d3686f051cf978
19 changes: 17 additions & 2 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
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;
Expand All @@ -76,12 +78,19 @@ public function needsPartFile() {
/** @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');
}

/**
Expand Down Expand Up @@ -721,8 +730,14 @@ private function getDirectoryMetaData(string $path): ?array {

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;
}
Expand Down