Hi,

I'm trying to personalise pages on a drupal site i'm working on for a client. It's high-traffic site, so performance is a big issue.
The site uses panels/page manager for it's layout.

What i want is the following:

  • Personalise certain content panes based on some data i have on the anonymous user (collected earlier)
  • Keep performance in check, without normale page caching

To accomplish this, some people in the community pointed me toward authcache as a means to accomplish this, but i'm not quite sure if/how i should go about implementing authcache to server my needs.

I've implemented authcache and everything seems to be working. The pages load quite fast, because whole pages get cached, except for panes i add "authcache"-caching to. These will get loaded in after the page loads. One of the problems i'm having is that these ajax calls take 2-3 seconds, which is way to long to be useful. I've tested this with a pane that holds the main menu, and with panes that just hold text, both are very slow.

Another problem is alternating the content that is retrieved based on some variables. For instance, i've added 2 panes of text and added authcaching to both with ajax. Both panes have visibility settings to show only if cookie == 1 for one pane and != 1 for the other pane.
Reloading the page while switching the cookie from 0 to 1 and back doesn't change the outcome of the ajax call(s).

Am i missing some settings or fundamental understanding of what the authcache plugin does and doesn't do?
Could the functionality i want even be accomplished with authcache?

Any help is greatly appreciated!

Comments

swigle created an issue. See original summary.

znerol’s picture

Personalise certain content panes based on some data i have on the anonymous user (collected earlier)

Where do you store this information? In the browser (cookies) or on the server (session)?

One of the problems i'm having is that these ajax calls take 2-3 seconds, which is way to long to be useful. I've tested this with a pane that holds the main menu, and with panes that just hold text, both are very slow.

In order to render panel panes, the authcache front controller needs to do a full bootstrap. I.e. this is the time your site needs to boot up and render a pane. I recommend to take a look at your site using xhprof in order to figure out what exactly is hogging resources.

Another problem is alternating the content that is retrieved based on some variables. For instance, i've added 2 panes of text and added authcaching to both with ajax. Both panes have visibility settings to show only if cookie == 1 for one pane and != 1 for the other pane. Reloading the page while switching the cookie from 0 to 1 and back doesn't change the outcome of the ajax call(s).

Authcache tries hard to cache fragments in the users browser (and also aggregates results from ajax calls in order to avoid making multiple round-trips to the server for the same fragment). After changing cookies in the browser, you have to assign a new random value to the aucp13n cookie. See #2653454: Trigger update of page fragment using js for some more background.

swigle’s picture

Thanks for your reply! (sorry for not replying earlier)

We're gathering information about the user and this gets sent to AWS for storage by way of an api. On every page load, this gets done and the call returns the current info about the current user, which we can use that pageview for personalisation.

I will look into xhprof. I also thought that there must be a bottleneck somewhere, because un-cached pages should not take 5+ seconds to get rendered. Hopefully xhprof wil shed some light on the issue.
If drupal speeds up to normal, i can test with more realistic loadtimes.

When i got the above working properly, i will look into the fragments. Maybe we'll choose a middel road for now and cache whole pages with authcache, one for every "type" of user we define. This would require custom groups to be created in authcache, but i think this should be possible.

swigle’s picture

Sorry to dreg this up again, but i've managed to make some progress. We've looked into the personalisations we want and concluded that caching entire pages with keys based on some of our own variables (with hook_authcache_key_properties) would suffice.

So we've succesfully implemented authcache on the live site of the client and everything works smooth and quick, for both authorized users as anonymous users. The next step was to implement our own logic to the authcache key with hook_authcache_key_properties sowe could create different caches for different groups of people. Neat!

But here comes the but; the whole cache key generation, whilst cool for logged in users, is totally bypassed for anonymous users. After rooting around in the code of authcache i found that for anon users, authcache_backend_anonymous_key() is used for key generation, totally skipping any custom changes to the cache keys. The only way to alter keys for anon users is by supplying a custom key generator, but this generator must be placed in the settings.php file. On that moment, my custom personalisation module for drupal hasn't loaded yet so i don't have the properties of the current user at my disposal for use in the key.

I can imagine this all was done for a reason, but for my case where i want to change content for anon users, this prehibits me from implementing my sollution.

I can hack the module ofcourse, but this is not something i want to do. Is there a chance a hook can be added for anon cache keys just like the way it is done for authorized users? I get the userdata from an external source on hook_boot() so i have all the information for forming a key at the time of hook_init().

Thnx in advance

znerol’s picture

The anonymous key needs to be calculated at a very early bootstrapping phase. At that point in time modules are not yet loaded - not even the bootstrap modules (in case you use #2480741: Introduce an option to deliver cached pages without initializing variables). I agree that this makes it quite cumbersome to alter the anonymous key.

In general I recommend to only take into account data which is already present in the request (e.g. cookies, server variables, environment variables, etc). E.g., if you want to vary the key according to the country of the client IP, then I suggest to use a webserver extension which makes that data available in every request. If you use nginx you even can run embedded lua scripts for every request. If the data is already present in the request before it gets to PHP, then the key callback function will be short and neat.

Another thing you could consider is to extract the key callback function into a separate file and just include_once that from within settings.php. That way you avoid cluttering your settings.php.

swigle’s picture

Thanks for your reply.

I've tested the sequence of the loaded modules and the data i need for the personalised key is available the moment authcache runs for authenticated users, so calculating a cache key with my variables isn't a problem.

Am i correct in assuming that the cache key calculations for an authenticated user and an anonymous user are done at different times during a pageview? Because for authenticated users, there is a hook available, but for anon users, there isn't. So the problem is that the whole hook system isn't initialized yet when the cache key for an anon user is calculated, is this correct?

If not, and all keys are calculated on hook_init(), then i don't see why there couldn't be a hook to alter the keys for an anon user. Is this only for performance reasons?

The only thing, besides altering the authcache module, which i don't want to do, is to alter my code to work with the key generator function in settings and let that function get the variables for the current user, and use them to calculate the cache key.
I'm reluctant to do this, because using a hook, like i do for authenticated users, is way more neat.

znerol’s picture

So the problem is that the whole hook system isn't initialized yet when the cache key for an anon user is calculated, is this correct?

Yes.

znerol’s picture

Status: Active » Fixed

Guess we are done here. Otherwise feel free to reopen.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.