Be careful with the logic - the Last-Modified header shouldn't be based on the client header (base it on the date the feed was last modifed). You should also send a relevant Etag since it's often also expected by clients using a conditional GET request.
Paddy Pádraic Brady http://blog.astrumfutura.com http://www.survivethedeepend.com OpenID Europe Foundation Irish Representative ________________________________ From: Hector Virgen <[email protected]> To: takeshin <[email protected]> Cc: [email protected] Sent: Thu, December 10, 2009 9:24:37 PM Subject: Re: [fw-general] Zend_Feed - sending proper headers You'll want to use a mix of server-side caching and client-side caching. The server-side caching can be done with Zend_Cache. That way if two separate users try to access the feed, your application only needs to build it once. For client-side caching, you'll need to analyze the request and send the correct response headers. I use something like this: public function viewAction() { $request = $this->getRequest(); $response = $this->getResponse(); // Enable browser caching $response->setHeader('Cache-Control', 'private, max-age=10800, pre-check=10800', true); $response->setHeader('Pragma', 'private', true); $response->setHeader('Expires', date(DATE_RFC822, strtotime(' 2 day')), true); // Check for client cache if (null !== ($modified = $request->getServer('HTTP_IF_MODIFIED_SINCE'))) { // User has cached page, send 304 "not modified" header $response->setHeader('Last-Modified', $modified, true); $response->setHttpResponseCode(304); } else { // User does not have cached page, build response body /* Your server-side caching code goes here */ $response->setBody($feed); } // Send response $response->sendResponse(); exit; } I hope this helps. -- Hector On Thu, Dec 10, 2009 at 12:48 PM, takeshin <[email protected]> wrote: > >>How to send feeds properly? > >>I want browser read whole file, only if it has new entries. > >>I read data from the database. Limit result to 15 items. >>Then create an array and pass it to the Zend_Feed. > >>Shall I cache the above steps with Zend_Cache + very long lifetime, >>and use a cache tag, clean cache entries by tag when new article is posted? > >>Then, is it enough to use send() method? >>Do browsers read last-modified entry from the feed itself, >>or only from the HTTP headers? > >>-- >>regards >>takeshin > >>-- >>View this message in context: >>http://n4.nabble.com/Zend-Feed-sending-proper-headers-tp960516p960516.html >>Sent from the Zend Framework mailing list archive at Nabble.com. >
