Thanks to the Commerce ecosystem it became easy to put together extremely flexible online stores with Drupal. In order to showcase the capabilities, the Commerce Kickstart distribution has been created. The second major version brought a shiny theme. Therefore this project is extremely helpful when demoing the look and feel of customized Drupal sites. However if you ever tried it out, you probably noticed that the system slows down as soon as you put something in your shopping cart. Using Authcache it is possible to get rid of this delay by serving up cached pages even for users with an open session.

This is a step-by-step guide on setting up Authcache 2 in order to boost the performance of Commerce Kickstart 2.

Step 1: Setup Commerce Kickstart

Setup Commerce Kickstart by following the instructions. Then verify that the installation works.

If you do not feel setting up Commerce Kickstart and Authcache on a development environment, you may start a preconfigured instance on simplytest.me.

Step 2: Enable Drupal built-in page caching for anonymous users

Open the frontpage of your commerce kickstart instance and inspect the page load time using the developer tools of your browser (Firebug, Web Inspector, ...). Normally you should get a couple of hundred milliseconds.

Screenshot with page load time of commerce kickstart without page caching

Now login as administrator and navigate to Site Settings - Configuration - Performance and enable the checkbox Cache pages for anonymous users. Save settings and logout again.

Screenshot with drupal performance settings

Step 3: Explore caching behavior for anonymous users

The first time you visit the frontpage you will not notice any difference in page load times. However on subsequent page requests the page load times should drop by about a factor of 10 to under 50 milliseconds.

Screenshot with page load time of commerce kickstart with page caching

Now navigate to a product page of your choice and put something into your shopping cart. Return to the frontpage and repeat the measurement. Note that the page load time will be back up around some hundred milliseconds again, only because there is an item in your shopping cart. This is where authcache comes in.

Screenshot with page load time of commerce kickstart with page caching deactivated due to an open session

Step 4: Download and install Authcache 2.x

Download and unpack Authcache 2 into the drupal commerce modules directory. Then enable the following modules:

  • Authcache
  • Authcache Ajax
  • Authcache Builtin Storage Backend
  • Authcache Comment
  • Authcache Form
  • Authcache Personazilation API
  • Authcache Views

Also you may enable Authcache Debug. This module provides a widget indicating whether a page was delivered from cache and also the reason when caching was not possible.

After enabling the modules, you will be notified that the builtin storage backend needs to be configured properly before it works. Open your settings.php (most probably sites/default/settings.php) and add the following line:

$conf['cache_backends'][] = 'sites/all/modules/authcache/authcache.cache.inc';
$conf['cache_backends'][] = 'sites/all/modules/authcache/modules/authcache_builtin/authcache_builtin.cache.inc';

Also disable the drupal core page caching mechanism by reverting the configuration from step 3.

After that navigate to Site Settings - Site reports - Status report and ensure that there are no error messages showing up.

Step 5: Configure authcache

Navigate to Site Settings - Configuration - Authcache and enable authcache for anonymous and authenticated users.

Screenshot showing the authcache settings

Open the context menu on the shopping cart located in the top right corner of the Checkout button in the top-bar then choose Edit view. Open the Advanced settings of the shopping cart view and click on Authcache: Disabled.

Screenshot describing the path to the authcache settings of the shopping cart block

Enable the checkbox and click on Apply.

Screenshot showing the authcache view settings

Finally save the changes to the view.

Step 6: Explore caching behavior with authcache enabled

Logout from the administrator account and reproduce the test sequence from Step 3. Verify that pages are cached and served from cache even when the shopping cart contains one or more products.

Screenshot with page load time of commerce kickstart with page caching working even though a session is open

Where to continue

After working through this tutorial you should have an idea on how Authcache works and what it can do to help speeding up page load times for users with an open session. Additional documentation is linked form the project page.

Comments

Mario Baron’s picture

This is not really working for me. I have configured the Authcache properly and in debug I am getting the HIT result so thats all well and fine. The Shopping cart block view has also been configured as instructed above. Pages are cached so thats not an issue however, if the user visited a few pages before adding a product to cart if for whatever reason that user leaves the cart and returns to one of the pages previously visited the shopping cart view will return the "Shopping cart empty" value even thou there is an item inside the shopping cart.

znerol’s picture

Please file a support request.

WillowDigit’s picture

I also could not get it working until I enabled Authcache blocks and then enabled it on the Cart View Block in the block admin page. Now it works great. I've been reading the threads on the integration between Authcache and Boost. Exciting!

WillowDigit

candelas’s picture

There is a new module that makes "Commerce Add to Car" Form work and changes the user name in pages.

//trying to answer one question for each one that i make.
//this way, drupal will be more friendly and strong