diff options
author | icewind1991 <robin@icewind.nl> | 2014-03-07 13:29:47 +0100 |
---|---|---|
committer | icewind1991 <robin@icewind.nl> | 2014-03-07 13:29:47 +0100 |
commit | 3eb58d9973706b1cc3f51f024e362779d278ee49 (patch) | |
tree | e5128a5e473d5e869a0bef1764f09e03cf05a51b /lib | |
parent | ba3f5fe53ad6ed9d056af15d578df3cd66f03ef0 (diff) | |
parent | a8c67dc675d21c6c8167c6477157a07d372bc410 (diff) | |
download | nextcloud-server-3eb58d9973706b1cc3f51f024e362779d278ee49.tar.gz nextcloud-server-3eb58d9973706b1cc3f51f024e362779d278ee49.zip |
Merge pull request #7529 from owncloud/getlocalfile-cache
Add caching for getLocalFile on remote storages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/storage/common.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 9e826dd6192..3c078d7b1b4 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -27,6 +27,11 @@ abstract class Common implements \OC\Files\Storage\Storage { protected $watcher; protected $storageCache; + /** + * @var string[] + */ + protected $cachedFiles = array(); + public function __construct($parameters) { } @@ -122,11 +127,13 @@ abstract class Common implements \OC\Files\Storage\Storage { public function file_put_contents($path, $data) { $handle = $this->fopen($path, "w"); + $this->removeCachedFile($path); return fwrite($handle, $data); } public function rename($path1, $path2) { if ($this->copy($path1, $path2)) { + $this->removeCachedFile($path1); return $this->unlink($path1); } else { return false; @@ -137,6 +144,7 @@ abstract class Common implements \OC\Files\Storage\Storage { $source = $this->fopen($path1, 'r'); $target = $this->fopen($path2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); + $this->removeCachedFile($path2); return $result; } @@ -162,13 +170,14 @@ abstract class Common implements \OC\Files\Storage\Storage { } public function getLocalFile($path) { - return $this->toTmpFile($path); + return $this->getCachedFile($path); } /** * @param string $path + * @return string */ - private function toTmpFile($path) { //no longer in the storage api, still useful here + protected function toTmpFile($path) { //no longer in the storage api, still useful here $source = $this->fopen($path, 'r'); if (!$source) { return false; @@ -352,4 +361,15 @@ abstract class Common implements \OC\Files\Storage\Storage { // default, which is not local return false; } + + protected function getCachedFile($path) { + if (!isset($this->cachedFiles[$path])) { + $this->cachedFiles[$path] = $this->toTmpFile($path); + } + return $this->cachedFiles[$path]; + } + + protected function removeCachedFile($path) { + unset($this->cachedFiles[$path]); + } } |