Source for file HTTP_Cached.php
Documentation is available at HTTP_Cached.php
* Cache_Lite is needed to cache the feeds
require_once 'Cache/Lite.php';
include_once 'HTTP/Request.php';
class Services_ExchangeRates_Transport_HTTP_Cached {
function Services_ExchangeRates_Transport_HTTP_Cached ($cache, $request) {
$cache = new Cache_Lite ();
$request = new HTTP_Request ();
$this->request = $request;
* Retrieves data from cache, if it's there. If it is, but it's expired,
* it performs a conditional GET to see if the data is updated. If it
* isn't, it down updates the modification time of the cache file and
* returns the data. If the cache is not there, or the remote file has been
* modified, it is downloaded and cached.
* @param string URL of remote file to retrieve
* @return string File contents
if ($data = $this->cache->get ($cacheID)) {
// if $cache->get($cacheID) found the file, but it was expired,
// $cache->_file will exist
if (isset ($this->cache->_file ) && file_exists($this->cache->_file )) {
$this->request->addHeader ('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($this->cache->_file )) . " GMT");
$this->request->sendRequest ();
if (!($this->request->getResponseCode () == 304 )) {
// data is changed, so save it to cache
$data = $this->request->getResponseBody ();
$this->cache->save ($data, $cacheID);
// retrieve the data, since the first time we did this failed
if ($data = $this->cache->get ($cacheID, 'default', true )) {
Documentation generated on Mon, 11 Mar 2019 15:28:43 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|