add Cache::getStatus
This commit is contained in:
parent
c815fd5a5c
commit
13515effc9
2 changed files with 39 additions and 0 deletions
29
lib/files/cache/cache.php
vendored
29
lib/files/cache/cache.php
vendored
|
@ -9,6 +9,11 @@
|
|||
namespace OC\Files\Cache;
|
||||
|
||||
class Cache {
|
||||
const NOT_FOUND = 0;
|
||||
const PARTIAL = 1; //only partial data available, file not cached in the database
|
||||
const SHALLOW = 2; //folder in cache, but not all child files are completely scanned
|
||||
const COMPLETE = 3;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Storage\Storage
|
||||
*/
|
||||
|
@ -233,4 +238,28 @@ class Cache {
|
|||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage=?');
|
||||
$query->execute(array($this->storageId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
|
||||
*/
|
||||
public function getStatus($file) {
|
||||
$pathHash = md5($file);
|
||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
||||
$result = $query->execute(array($this->storageId, $pathHash));
|
||||
if ($row = $result->fetchRow()) {
|
||||
if ((int)$row['size'] === -1) {
|
||||
return self::SHALLOW;
|
||||
} else {
|
||||
return self::COMPLETE;
|
||||
}
|
||||
} else {
|
||||
if (isset($this->partial[$file])) {
|
||||
return self::PARTIAL;
|
||||
} else {
|
||||
return self::NOT_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
tests/lib/files/cache/cache.php
vendored
10
tests/lib/files/cache/cache.php
vendored
|
@ -101,6 +101,16 @@ class Cache extends \UnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
function testStatus() {
|
||||
$this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo'));
|
||||
$this->cache->put('foo', array('size' => -1));
|
||||
$this->assertEquals(\OC\Files\Cache\Cache::PARTIAL, $this->cache->getStatus('foo'));
|
||||
$this->cache->put('foo', array('size' => -1, 'mtime' => 20, 'mimetype' => 'foo/file'));
|
||||
$this->assertEquals(\OC\Files\Cache\Cache::SHALLOW, $this->cache->getStatus('foo'));
|
||||
$this->cache->put('foo', array('size' => 10));
|
||||
$this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo'));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->cache->clear();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue