|
15 | 15 | use Ivory\HttpAdapter\Event\Subscriber\StatusCodeSubscriber; |
16 | 16 | use Ivory\HttpAdapter\HttpAdapterInterface; |
17 | 17 | use \Prismic\Cache\CacheInterface; |
18 | | -use \Prismic\Cache\DefaultCache; |
| 18 | +use \Prismic\Cache\ApcCache; |
| 19 | +use \Prismic\Cache\NoCache; |
19 | 20 |
|
20 | 21 | const PREVIEW_COOKIE = "io.prismic.preview"; |
21 | 22 |
|
@@ -63,7 +64,7 @@ private function __construct($data, $accessToken = null, HttpAdapterInterface $h |
63 | 64 | $this->data = $data; |
64 | 65 | $this->accessToken = $accessToken; |
65 | 66 | $this->httpAdapter = is_null($httpAdapter) ? self::defaultHttpAdapter() : $httpAdapter; |
66 | | - $this->cache = is_null($cache) ? new DefaultCache() : $cache; |
| 67 | + $this->cache = is_null($cache) ? self::defaultCache() : $cache; |
67 | 68 | } |
68 | 69 |
|
69 | 70 | /** |
@@ -291,7 +292,7 @@ public function getHttpAdapter() |
291 | 292 | */ |
292 | 293 | public static function get($action, $accessToken = null, HttpAdapterInterface $httpAdapter = null, CacheInterface $cache = null) |
293 | 294 | { |
294 | | - $cache = is_null($cache) ? new DefaultCache() : $cache; |
| 295 | + $cache = is_null($cache) ? self::defaultCache() : $cache; |
295 | 296 | $cacheKey = $action . (is_null($accessToken) ? "" : ("#" . $accessToken)); |
296 | 297 | $apiData = $cache->get($cacheKey); |
297 | 298 | $api = $apiData ? new Api(unserialize($apiData), $accessToken, $httpAdapter, $cache) : null; |
@@ -333,6 +334,17 @@ function ($ref) { |
333 | 334 | } |
334 | 335 | } |
335 | 336 |
|
| 337 | + /** |
| 338 | + * Use the APC cache if APC is activated on the server, otherwise fallback to the noop cache (no cache) |
| 339 | + */ |
| 340 | + public static function defaultCache() |
| 341 | + { |
| 342 | + if (extension_loaded('apc') && ini_get('apc.enabled')) { |
| 343 | + return new ApcCache(); |
| 344 | + } |
| 345 | + return new NoCache(); |
| 346 | + } |
| 347 | + |
336 | 348 | /** |
337 | 349 | * The default configuration of the HTTP adapter used in the kit; this is entirely overridable by passing |
338 | 350 | */ |
|
0 commit comments