Eccube\Util\Cache::clear PHP Method

clear() public static method

doctrine, profiler, twig によって生成されたキャッシュディレクトリを削除する. キャッシュは $app['config']['root_dir'].'/app/cache' に生成されます.
public static clear ( Application $app, boolean $isAll, boolean $isTwig = false ) : boolean
$app Eccube\Application
$isAll boolean .gitkeep を残してすべてのファイル・ディレクトリを削除する場合 true, 各ディレクトリのみを削除する場合 false
$isTwig boolean Twigキャッシュファイルのみ削除する場合 true
return boolean 削除に成功した場合 true
    public static function clear($app, $isAll, $isTwig = false)
    {
        $cacheDir = $app['config']['root_dir'] . '/app/cache';
        $filesystem = new Filesystem();
        if ($isAll) {
            $finder = Finder::create()->in($cacheDir)->notName('.gitkeep');
            $filesystem->remove($finder);
        } elseif ($isTwig) {
            if (is_dir($cacheDir . '/twig')) {
                $finder = Finder::create()->in($cacheDir . '/twig');
                $filesystem->remove($finder);
            }
        } else {
            if (is_dir($cacheDir . '/doctrine')) {
                $finder = Finder::create()->in($cacheDir . '/doctrine');
                $filesystem->remove($finder);
            }
            if (is_dir($cacheDir . '/profiler')) {
                $finder = Finder::create()->in($cacheDir . '/profiler');
                $filesystem->remove($finder);
            }
            if (is_dir($cacheDir . '/twig')) {
                $finder = Finder::create()->in($cacheDir . '/twig');
                $filesystem->remove($finder);
            }
            if (is_dir($cacheDir . '/translator')) {
                $finder = Finder::create()->in($cacheDir . '/translator');
                $filesystem->remove($finder);
            }
        }
        if (function_exists('opcache_reset')) {
            opcache_reset();
        }
        if (function_exists('apc_clear_cache')) {
            apc_clear_cache('user');
            apc_clear_cache();
        }
        if (function_exists('wincache_ucache_clear')) {
            wincache_ucache_clear();
        }
        return true;
    }

Usage Example

Beispiel #1
0
 public function testClear()
 {
     file_put_contents($this->app['config']['root_dir'] . '/app/cache/.dummykeep', 'test');
     // 'doctrine', 'profiler', 'twig' ディレクトリを削除
     Cache::clear($this->app, false);
     $finder = new Finder();
     $iterator = $finder->ignoreDotFiles(false)->in($this->app['config']['root_dir'] . '/app/cache')->files();
     foreach ($iterator as $fileinfo) {
         $this->assertStringEndsWith('keep', $fileinfo->getPathname(), 'keep しか存在しないはず');
     }
     $this->assertTrue($this->root->hasChild('app/cache/.gitkeep'), '.gitkeep は存在するはず');
     $this->assertTrue($this->root->hasChild('app/cache/.dummykeep'), '.dummykeep は存在するはず');
 }
All Usage Examples Of Eccube\Util\Cache::clear
Cache