public function testClean() { //Setting a file we know will have to be cleaned $home = getenv('HOME'); $dir_name = "{$home}/.terminus/cache"; $file_name = "{$dir_name}/" . $this->test_file_name; exec("touch -t 200401230000 {$file_name}"); $old_count = count(scandir($dir_name)); $this->file_cache->clean(); $new_count = count(scandir($dir_name)); $this->assertTrue($new_count < $old_count); //Running again when nothing new should be removed $this->file_cache->clean(); $new_new_count = count(scandir($dir_name)); $this->assertTrue($new_count == $new_new_count); }
/** * @return FileCache */ public static function get_cache() { static $cache; if (!$cache) { $home = getenv('HOME'); if (!$home) { // sometime in windows $HOME is not defined $home = getenv('HOMEDRIVE') . '/' . getenv('HOMEPATH'); } $dir = getenv('TERMINUS_CACHE_DIR') ?: "{$home}/.terminus/cache"; // 6 months, 300mb $cache = new FileCache($dir, 86400, 314572800); } $cache->clean(); return $cache; }
/** * @return FileCache */ public static function get_cache() { static $cache; if (!$cache) { $home = getenv('HOME'); if (!$home) { // sometime in windows $HOME is not defined $home = getenv('HOMEDRIVE') . '/' . getenv('HOMEPATH'); } $dir = getenv('TERMINUS_CACHE_DIR') ?: "{$home}/.terminus/cache"; // 6 months, 300mb $cache = new FileCache($dir, 86400, 314572800); // clean older files on shutdown with 1/50 probability if (0 === mt_rand(0, 50)) { register_shutdown_function(function () use($cache) { $cache->clean(); }); } } return $cache; }
/** * Sets a file cache instance to a class property * * @return void */ public static function setCache() { $home = getenv('HOME'); if (!$home) { //Sometimes in Windows, $HOME is not defined. $home = getenv('HOMEDRIVE') . '/' . getenv('HOMEPATH'); } $dir = getenv('TERMINUS_CACHE_DIR'); if (!$dir) { $dir = "{$home}/.terminus/cache"; } // 6 months, 300mb $cache = new FileCache($dir, 86400, 314572800); $cache->clean(); self::$cache = $cache; }