Skip to content

Commit

Permalink
Merge branch 'wip-MDL-50932-master' of git://github.com/marinaglancy/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
David Monllao committed Aug 17, 2015
2 parents 87aadca + 7b3c5e0 commit 7d8edf6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cache/stores/file/lib.php
Expand Up @@ -341,8 +341,8 @@ public function get($key) {
$maxtime = cache::now() - $ttl;
}
$readfile = false;
if ($this->prescan && array_key_exists($key, $this->keys)) {
if (!$ttl || $this->keys[$filename] >= $maxtime && file_exists($file)) {
if ($this->prescan && array_key_exists($filename, $this->keys)) {
if ((!$ttl || $this->keys[$filename] >= $maxtime) && file_exists($file)) {
$readfile = true;
} else {
$this->delete($key);
Expand Down
30 changes: 30 additions & 0 deletions cache/stores/file/tests/file_test.php
Expand Up @@ -44,4 +44,34 @@ class cachestore_file_test extends cachestore_tests {
protected function get_class_name() {
return 'cachestore_file';
}

/**
* Testing cachestore_file::get with prescan enabled and with
* deleting the cache between the prescan and the call to get.
*
* The deleting of cache simulates some other process purging
* the cache.
*/
public function test_cache_get_with_prescan_and_purge() {
global $CFG;

$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test');
$name = 'File test';

$path = make_cache_directory('cachestore_file_test');
$cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
$cache->initialise($definition);

$cache->set('testing', 'value');

$path = make_cache_directory('cachestore_file_test');
$cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
$cache->initialise($definition);

// Let's pretend that some other process purged caches.
remove_dir($CFG->cachedir.'/cachestore_file_test', true);
make_cache_directory('cachestore_file_test');

$cache->get('testing');
}
}

0 comments on commit 7d8edf6

Please sign in to comment.