[support] how cache works: on the fly content creation (not node) and caching

Ivan Sergio Borgonovo mail at webthatworks.it
Mon Jan 4 15:24:11 UTC 2010


On Mon, 4 Jan 2010 14:58:01 +0100
Ivan Sergio Borgonovo <mail at webthatworks.it> wrote:

> How am I going to influence when a cached page is wiped other than
> setting a minimum lifetime?
> Even in D7 $expire is not accessible/configurable directly if at
> all. A not always working trick could be to set
> $GLOBALS['conf']['cache_lifetime'] /* didn't check if it is the
> right place but I guess you got the idea */
> but in many places $expire is hard coded.
> 
> Furthermore there is no way I can see to "late invalidate" a page
> cache.

or just skip cache...

> eg. let's say I saved something like "from this moment on, don't
> use cache for A, B and C" in the session... since hook_init fire
> later than when the cache is already loaded, I'm obliged to return
> the cached version.

> What method am I going to use to offer custom content to anonymous
> users without invalidating the cache for everyone else?

> Suppose I just would like to add a greeting at the top of all the
> pages for all users (anonymous) that just took the time to fill in
> their name (I bet you can find more useful examples)...
> I set a cookie/flag in the session... but whatever I write will
> come into play to late to decide if I can serve a cached page or
> not.
> 
> How am I going to handle this?
> Even having block and page cache separated this force to turn off
> page cache for everyone even if it reduces the cost of completely
> regenerating content.
> There should be a way to disable cache use at least according to
> $_SESSION content.

It seems the problem is nearly solved in D7

function _drupal_bootstrap($phase) {
...
$cache = drupal_page_get_cache();
        // If there is a cached page, display it.
        if (is_object($cache)) {
          // If the skipping of the bootstrap hooks is not enforced,
          call
          // hook_boot.
          if (variable_get('page_cache_invoke_hooks', TRUE)) {
            bootstrap_invoke_all('boot');

But if you put something into $_SESSION, then the page is set as non
cacheable in drupal_session_initialize (I think
drupal_session_initialize is called before than the cache phase).

Still if for any reason someone would like to externally turn off
the cache on other kind of input (IP?) that won't be possible.

Wouldn't it be better to call hook_boot before cache is loaded?

I'm going to hack D5/D6 core to switch cacheability of pages
according to $_SESSION, since this is going to come very handy.

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



More information about the support mailing list