In D6, there is the major limitation of having all token values loaded whenever any token value is loaded. Currently the onus is on the module developer (it seems) to ensure that they aren't overdoing their token requests.

As I added a new custom token today, I was distraught to find that it was being calculated on every page load, on my site. This was traceable back to the "googleanalytics_footer" function. If any tokens are expensive to recalculate, that could be disastrous.

I propose that GA module cache the contents of the footer, somehow (..Per user, possibly? Or even per session?) to keep from having to re-do expensive computations on every pageview. Apologies if this has been discussed elsehwhere - I searched.

Comments

hass’s picture

Title: All token values loaded on every page, if using custom variables » Implement token caching API for expensive tokens
Project: Google Analytics » Token
Version: 6.x-3.x-dev » 6.x-1.x-dev
Category: bug » feature

It has for sure never been discussed here in the GA queue and I believe your idea is not possible in this late stage. Only think about tokens that depend on specific pages. How should the GA module know if the token is user, role, node or site specific? e.g. [node:url] or [current-page:url] change with every page - I can only guess if it does or not... At least GA cannot tell if and how to cache a token value.

The code that reads the values from database may be able to cache. I guess this caching must be part of your custom token code - otherwise all modules implementing tokens can only guess if a value can be cached or not. I'm not aware of a build in caching logic in token module, but it would be a good place to provide a token specific cache API in a consistent and developer friendly way.

I'm moving this to token module queue for review over there.

Offlein’s picture

Thanks Hass. As I understand it, it's been discussed over and over again by the Token crew. (But maybe now that we're here, someone can weigh in on that for certain.)

It might be beneficial for GA module to implement some, uh, common segments or something, to be called in lieu of the token? And perhaps in lieu of that, at least a warning that every token in your site will be called on every pageview if you utilize that.

Based off what I understand -- which is, again, admittedly not a ton -- Token was never really architected to be used for something like that.

hass’s picture

Duplicate of #619892: Per-token cache and flushing. sounds like there is already a cache...