Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#9 from weierophinney/f…
Browse files Browse the repository at this point in the history
…eature/cache_beta2

Feature/cache beta2
  • Loading branch information
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
namespace Zend\Feed\Reader;

use Zend\Http,
use Zend\Cache\Storage\Adapter as CacheAdapter,
Zend\Http,
Zend\Loader;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ class Reader
/**
* Cache instance
*
* @var \Zend\Cache\Frontend\Core
* @var CacheAdapter
*/
protected static $_cache = null;

Expand Down Expand Up @@ -111,7 +112,7 @@ class Reader
/**
* Get the Feed cache
*
* @return \Zend\Cache\Frontend\Core
* @return CacheAdapter
*/
public static function getCache()
{
Expand All @@ -121,10 +122,10 @@ public static function getCache()
/**
* Set the feed cache
*
* @param \Zend\Cache\Frontend\Core $cache
* @param CacheAdapter $cache
* @return void
*/
public static function setCache(\Zend\Cache\Frontend\Core $cache)
public static function setCache(CacheAdapter $cache)
{
self::$_cache = $cache;
}
Expand Down Expand Up @@ -217,13 +218,13 @@ public static function import($uri, $etag = null, $lastModified = null)
$cacheId = 'Zend_Feed_Reader_' . md5($uri);

if (self::$_httpConditionalGet && $cache) {
$data = $cache->load($cacheId);
$data = $cache->getItem($cacheId);
if ($data) {
if ($etag === null) {
$etag = $cache->load($cacheId.'_etag');
$etag = $cache->getItem($cacheId.'_etag');
}
if ($lastModified === null) {
$lastModified = $cache->load($cacheId.'_lastmodified');;
$lastModified = $cache->getItem($cacheId.'_lastmodified');;
}
if ($etag) {
$headers->addHeaderLine('If-None-Match', $etag);
Expand All @@ -240,17 +241,17 @@ public static function import($uri, $etag = null, $lastModified = null)
$responseXml = $data;
} else {
$responseXml = $response->getBody();
$cache->save($responseXml, $cacheId);
$cache->setItem($cacheId, $responseXml);
if ($response->getHeader('ETag')) {
$cache->save($response->getHeader('ETag'), $cacheId.'_etag');
$cache->setItem($cacheId . '_etag', $response->getHeader('ETag'));
}
if ($response->getHeader('Last-Modified')) {
$cache->save($response->getHeader('Last-Modified'), $cacheId.'_lastmodified');
$cache->setItem($cacheId . '_lastmodified', $response->getHeader('Last-Modified'));
}
}
return self::importString($responseXml);
} elseif ($cache) {
$data = $cache->load($cacheId);
$data = $cache->getItem($cacheId);
if ($data !== false) {
return self::importString($data);
}
Expand All @@ -259,7 +260,7 @@ public static function import($uri, $etag = null, $lastModified = null)
throw new Exception('Feed failed to load, got response code ' . $response->getStatusCode());
}
$responseXml = $response->getBody();
$cache->save($responseXml, $cacheId);
$cache->setItem($cacheId, $responseXml);
return self::importString($responseXml);
} else {
$response = $client->send();
Expand Down

0 comments on commit 2914396

Please sign in to comment.