Beispiel #1
0
 /**
  * @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;
 }
Beispiel #2
0
 public function testRemove()
 {
     $file_name = $this->getFileName();
     setOutputDestination($file_name);
     $removed = $this->file_cache->remove($this->test_file_name);
     $this->assertTrue($removed);
     $removed = $this->file_cache->remove($this->test_file_name);
     $this->assertFalse($removed);
 }
Beispiel #3
0
 /**
  * @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;
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * Removes a site from the sites cache
  *
  * @param string $sitename Name of site to remove from array
  * @return void
  */
 public function remove($sitename)
 {
     $cache = (array) $this->cache->getData($this->cachekey, array('decode_array' => true));
     unset($cache[$sitename]);
     $this->cache->putData($this->cachekey, $cache);
 }