Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.4

Request #4754 [PATCH] Add cache length to API
Submitted: 2005-07-05 17:20 UTC Modified: 2005-07-18 04:40 UTC
From: aron-phppear at sightspeed dot com Assigned: mike
Status: Closed Package: HTTP_Download
PHP Version: 5.0.4 OS:
Roadmaps: (Not assigned)    
Subscription  


 [2005-07-05 17:20 UTC] aron-phppear at sightspeed dot com
Description: ------------ This patch allows the ability to set via the Class api how long a file should be cached for instead of just forcing the setting to 0 which forces a revalidate everytime. The default time is 3600 seconds which is one hour. Reproduce code: --------------- --- Download.php.orig 2005-06-06 18:11:10.000000000 -0700 +++ Download.php 2005-07-05 15:10:21.000000000 -0700 @@ -140,6 +140,22 @@ * @var bool */ var $cache = true; + + /** + * Length of time (in seconds) the cache is valid for. Only valid if caching is enabled. + * + * @access protected + * @var int + */ + var $cacheTime = 3600; + + /** + * If we are allowing caching, should a proxy be allowed to cache the file + * + * @access protected + * @var string + */ + var $cachePrivacy = 'public'; /** * Size of download @@ -166,7 +182,7 @@ var $headers = array( 'Content-Type' => 'application/x-octetstream', 'Pragma' => 'cache', - 'Cache-Control' => 'public, must-revalidate, max-age=0', + 'Cache-Control' => 'public, must-revalidate, max-age=3600', 'Accept-Ranges' => 'bytes', 'X-Sent-By' => 'PEAR::HTTP::Download' ); @@ -401,6 +417,22 @@ { $this->cache = (bool) $cache; } + + /** + * Set the length of time (in seconds) that the cache should be valid + * for. Ex: 3600 is one hour + * + * If set to 0, browser should reverify at each use. + * + * @access public + * @return void + * @param int $cache whether to allow caching + */ + function setCacheValidTime($cacheTime = 0) + { + $this->cacheTime = (int) $cacheTime; + $this->headers['Cache-Control'] = $this->cachePrivacy .', must-revalidate, max-age=' . $this->cacheTime; + } /** * Whether to allow proxies to cache @@ -418,8 +450,9 @@ { case 'private': case 'public': + $this->cachePrivacy = $cache; $this->headers['Cache-Control'] = - $cache .', must-revalidate, max-age=0'; + $this->cachePrivacy .', must-revalidate, max-age=' . $this->cacheTime; return true; break; }

Comments

 [2005-07-18 04:40 UTC] mike
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. Implemented - KISS