Download src/Shared/Infrastructure/CacheManager.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Shared/Infrastructure/CacheManager.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Shared/Infrastructure/CacheManager.php
-
curl -L -o CacheManager.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Shared/Infrastructure/CacheManager.php
1.2 kB
| declare(strict_types=1); | |
| namespace Shared\Infrastructure; | |
| use Easy\Container\Attributes\Inject; | |
| use Psr\Cache\CacheItemPoolInterface; | |
| use Psr\SimpleCache\CacheInterface; | |
| use RecursiveDirectoryIterator; | |
| use RecursiveIteratorIterator; | |
| class CacheManager | |
| { | |
| public function __construct( | |
| private CacheItemPoolInterface $cacheItemPool, | |
| private CacheInterface $cache, | |
| #[Inject('config.dirs.cache')] | |
| private string $cacheDir, | |
| ) { | |
| } | |
| public function clearCache(): void | |
| { | |
| $this->cacheItemPool->clear(); | |
| $this->cache->clear(); | |
| $this->clearCacheDir(); | |
| } | |
| private function clearCacheDir(): void | |
| { | |
| $iterator = new RecursiveIteratorIterator( | |
| new RecursiveDirectoryIterator( | |
| $this->cacheDir, | |
| RecursiveDirectoryIterator::SKIP_DOTS | |
| ), | |
| RecursiveIteratorIterator::CHILD_FIRST | |
| ); | |
| foreach ($iterator as $path) { | |
| if ($path->isDir()) { | |
| rmdir($path->getPathname()); | |
| } elseif ($path->getFilename() != '.gitkeep') { | |
| unlink($path->getPathname()); | |
| } | |
| } | |
| } | |
| } | |