Hinting cache from views (vary cache time by object age)
|Reported by:||Owned by:||nobody|
|Component:||Core (Cache system)||Version:|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently cache system uses rather simple way to specify expiration time: it is either some global value for per-site cache, or decorator's parameter for per-view cache. In reality in many cases it depends on content.
For example, any news-oriented site (newspaper, blog, message board, ad place, and so on) rarely (if ever) changes archived articles. It is normal to go and change a recent article --- some typos, omissions, and recent development may warrant updates. In this case it makes sense to set hours (days? weeks?) for old articles, and few minutes for recent ones. Possibly some gradations would be required depending on age of underlying document.
It is quite possible to find other influences on cache item expiration time: tags, trends of user's activity, and so on.
I propose to add a property to response object, which will indicate the desired expiration time. It can be set by view methods (or some custom middleware). If it is set, it's used by cache middleware. If not, existing mechanism is used.
This change doesn't break existing code. Required code changes are rather trivial --- existing cache middleware uses similar mechanism already (request object is used instead of response object). That's why I don't submit a patch this time --- it boils down to invention of right name for the property. I trust you guys would be far more consistent than me.