Caching at HTTP-Level

This is more of a proof-of-concept: I wanted to implement caching at http-level in an effort to save network bandwidth. It works, but I feel it is nowhere near where I'd use it in production, so any comments are welcome.

This filter can be used quite similar to COutputCache (See the guide on filters for more). Last-Modified is favoured over ETags for SEO reasons. I decided not to use both at once since that would add unnecessary overhead: According to the RFCs, a client would have to check both.

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code

The idea is to cache entire pages on the client side. Caching on the server side will spare you from rendering the same thing over and over again. Caching on the client side will also eliminate the need to transmit that page

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code

Thank you for a good filter. I've modified some codes direct to my opinion.

I think we should move lastModifed and eTag into lazy calculating. Why?
We do not need to apply this filter on all actions of a controller. For example, with a controller 'Article', we should apply this filter on action 'view' only, the others (edit, comment, vote) is out of this filter. So, if we always calculate ETag (or LastModified) when the Controller::filters() function is called, it wastes the resources.

Thanks for your input. The lazy calculation approach is a very valid point. However, I think a set of expressions like COutputCache.varyByExpression were a better way of implementing this, so we would have a eTagExpression and lastModifiedExpression. IMHO, that's a cleaner way of doing this. evaluateExpression() would still allow to set callbacks in place.

I'll be using this in a new project soon, so stay tuned for updates

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code

Update: I plan to release this as an extension to Yii. I think the chances of this landing in upstream Yii are rather slim. I've tried to tie the existing cache dependency system into the filter but that'll greatly increase complexity while bringing little benefit over putting a CCacheDependency into HttpCacheFilter.etagSeed.

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code

Hm, after consulting the RFC again, it looks like this filter isn't complying to HTTP/1.1 ... If a server is able to create both, last modified time and ETag, it should actually send them all out. I'll work this over if I find the time.

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code