Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

class ObjectStoreStorage extends \OC\Files\Storage\Common {

/**
* @var \OC\Files\ObjectStore\StatCache $statCache
*/
private $statCache;
/**
* @var array
*/
Expand Down Expand Up @@ -66,6 +70,10 @@ public function __construct($params) {
if (isset($params['objectPrefix'])) {
$this->objectPrefix = $params['objectPrefix'];
}

// Initialize stat cache
$this->statCache = new StatCache();

//initialize cache with root directory in cache
if (!$this->is_dir('/')) {
$this->mkdir('/');
Expand Down Expand Up @@ -205,8 +213,17 @@ public function unlink($path) {

public function stat($path) {
$path = $this->normalizePath($path);
$cacheEntry = $this->getCache()->get($path);

// Try to get from stat cache if possible
$cacheEntry = $this->statCache->get($path);
if (!$cacheEntry) {
// No stat, fetch from filecache
$cacheEntry = $this->getCache()->get($path);
}

if ($cacheEntry instanceof CacheEntry) {
// Try to put filecache entry in stat cache if possible
$this->statCache->put($path, $cacheEntry);
return $cacheEntry->getData();
} else {
return false;
Expand Down Expand Up @@ -489,4 +506,15 @@ public function restoreVersion($internalPath, $versionId) {
}
return parent::restoreVersion($internalPath, $versionId);
}

/**
* @inheritdoc
*/
public function getMetaData($path) {
$this->statCache->enable($path);
$data = parent::getMetaData($path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use stat cache only for the time of getMetaData call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used by file_exists, getMimeType, filesize etc read-only functions during getMetaData call

$this->statCache->disable($path);

return $data;
}
}
65 changes: 65 additions & 0 deletions lib/private/Files/ObjectStore/StatCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @author Piotr Mrowczynski <[email protected]>
*
* @copyright Copyright (c) 2018, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OC\Files\ObjectStore;

use OC\Files\Cache\CacheEntry;

class StatCache {

/**
* @var \OC\Files\Cache\CacheEntry[] $cache
*/
private $cache;

/**
* @var string[] $statCacheEnabled
*/
private $statCacheEnabled;

public function __construct() {
}

public function enable($path) {
$this->statCacheEnabled[$path] = true;
}

public function disable($path) {
unset($this->statCacheEnabled[$path]);
}

public function put($path, CacheEntry $cache) {
if ($this->isEnabled($path)) {
$this->cache[$path] = $cache;
}
}

public function get($path) {
if ($this->isEnabled($path) && isset($this->cache[$path])) {
return $this->cache[$path];
}
return false;
}

private function isEnabled($path) {
return isset($this->statCacheEnabled[$path]);
}
}