PhpFilesAdapter example

/** * @group time-sensitive */
class PhpFilesAdapterTest extends AdapterTestCase
{
    protected $skippedTests = [
        'testDefaultLifeTime' => 'PhpFilesAdapter does not allow configuring a default lifetime.',
    ];

    public function createCachePool(): CacheItemPoolInterface
    {
        return new PhpFilesAdapter('sf-cache');
    }

    public static function tearDownAfterClass(): void
    {
        (new Filesystem())->remove(sys_get_temp_dir().'/symfony-cache');
    }

    protected function isPruned(CacheItemPoolInterface $cache, string $name): bool
    {
        $getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');

        
CacheItem::class
        D;
    }

    /** * Returns the best possible adapter that your runtime supports. * * Using ApcuAdapter makes system caches compatible with read-only filesystems. */
    public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null): AdapterInterface
    {
        $opcache = new PhpFilesAdapter($namespace$defaultLifetime$directory, true);
        if (null !== $logger) {
            $opcache->setLogger($logger);
        }

        if (!self::$apcuSupported ??= ApcuAdapter::isSupported()) {
            return $opcache;
        }

        if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
            return $opcache;
        }

        

class PhpFilesAdapterAppendOnlyTest extends PhpFilesAdapterTest
{
    protected $skippedTests = [
        'testDefaultLifeTime' => 'PhpFilesAdapter does not allow configuring a default lifetime.',
        'testExpiration' => 'PhpFilesAdapter in append-only mode does not expiration.',
    ];

    public function createCachePool(): CacheItemPoolInterface
    {
        return new PhpFilesAdapter('sf-cache', 0, null, true);
    }
}
Home | Imprint | This part of the site doesn't use cookies.