[development] possible cache improvement

Ivan Sergio Borgonovo mail at webthatworks.it
Tue Jan 5 01:59:10 UTC 2010


Hi,

I was trying to solve a cache problem with D5/D6 and I thought to
check how D7 solved those problems.

Generally I was trying to have more control on page cache to still
be able to exploit it even when some content has to be "tailored"
for anonymous users or to switch cache off responding to "external"
input.

eg. suppose I'd like to show a greeting on all pages to people
having a certain IP or the site should write a message on all pages
to anonymous users that filled in a form or from time X to time Y I
should display a banner on all pages.

So pages may be retrieved from cache or not according to some
condition that I should verify at page request.

I may save something into $SESSION but still be willing to save
cached version of certain pages.

Furthermore I should be able to control $expire at content creation
time, not as a general parameter (some content may have a longer
expected TTL).

I started to partially solve this problem in D5/6 in
include/bootstrap.inc

if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' &&
count(drupal_set_message()) == 0 && $_SESSION['cacheable']!==false) {

Then I thought that modules could switch on/off cache for different
reasons...

So the above became

if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' &&
count(drupal_set_message()) == 0 &&
!in_array(false, $_SESSION['cacheable'], true)

I think a similar system could be applied to D7 and not just
consider un-cacheable a page if $SESSION is not empty.

Still this is not enough to decide if a page has to be returned from
cache or not depending on "external" events.
If hook_boot could be anticipated before the cache is filled this
could be exploited for controlling the cache too.

It would be nice to be able to explicitly set $expire at content
creation but this look a bit more invasive to obtain.

Does it sound reasonable?

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the development mailing list