netglue/prismic-php-kit

View on GitHub
src/Prismic/Cache/DefaultCache.php

Summary

Maintainability
A
0 mins
Test Coverage
D
62%
<?php
declare(strict_types=1);

namespace Prismic\Cache;

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

class DefaultCache
{

    public static function factory() : CacheItemPoolInterface
    {
        if (extension_loaded('apc') && ini_get('apc.enabled')) {
            return static::getApcCache();
        }
        return static::getArrayCache();
    }

    public static function getApcCache() : CacheItemPoolInterface
    {
        return new ApcuAdapter(\str_replace('\\', '', __NAMESPACE__));
    }

    public static function getArrayCache() : CacheItemPoolInterface
    {
        return new ArrayAdapter();
    }
}