Skip to content

Commit

Permalink
[#85] Make API cache TTL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan committed Jun 16, 2015
1 parent df984da commit ededeef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Prismic/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ public function getHttpAdapter()
* @param string $accessToken a permanent access token to use to access your content, for instance if your repository API is set to private
* @param HttpAdapterInterface $httpAdapter by default, the HTTP adapter uses CURL with a certain configuration, but you can override it here
* @param CacheInterface $cache Cache implementation
* @param int $apiCacheTTL max time to keep the API object in cache (in seconds)
* @throws \RuntimeException
* @return Api the Api object, useable to perform queries
*/
public static function get($action, $accessToken = null, HttpAdapterInterface $httpAdapter = null, CacheInterface $cache = null)
public static function get($action, $accessToken = null, HttpAdapterInterface $httpAdapter = null, CacheInterface $cache = null, $apiCacheTTL = 5)
{
$cache = is_null($cache) ? self::defaultCache() : $cache;
$cacheKey = $action . (is_null($accessToken) ? "" : ("#" . $accessToken));
Expand Down Expand Up @@ -339,7 +340,7 @@ function ($ref) {
);

$api = new Api($apiData, $accessToken, $httpAdapter, $cache);
$cache->set($cacheKey, serialize($apiData), 5);
$cache->set($cacheKey, serialize($apiData), $apiCacheTTL);

return $api;
}
Expand Down

1 comment on commit ededeef

@barrycarton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Please sign in to comment.