コード例 #1
0
ファイル: Cache.php プロジェクト: agpmedia/notoj
 public static function init($filepath, $global = true)
 {
     if (!is_file($filepath)) {
         if (!file_put_contents($filepath, "<?php\n", LOCK_EX)) {
             throw new \RuntimeException("Cannot write file {$filepath}");
         }
     }
     if (isset(self::$path2ns[$filepath])) {
         return self::$path2ns[$filepath];
     }
     $ns = $global ? 'global' : uniqid(true);
     $data = (array) (require $filepath);
     $useful = !empty($data['vesion']) && $data['version'] == self::CACHE_VERSION;
     self::$data[$ns] = $useful ? $data['data'] : array();
     self::$path[$ns] = $filepath;
     self::$isDirty[$ns] = false;
     self::$path2ns[$filepath] = $ns;
     if (!self::$registredShutdown) {
         register_shutdown_function(function () {
             Cache::save();
         });
         self::$registredShutdown = true;
     }
     return $ns;
 }
コード例 #2
0
ファイル: CacheTest.php プロジェクト: agpmedia/notoj
 /** @depends testCacheInit */
 function testCacheContent()
 {
     $obj = new ReflectionClass(__CLASS__);
     $arr = $obj->getAnnotations();
     $this->assertEquals(1, \Notoj\Cache::save());
     $this->assertEquals(0, \Notoj\Cache::save());
     $content = file_get_contents(CACHE);
     $this->assertTrue(strpos($content, sha1($obj->getDocComment())) !== FALSE);
 }