1. Documentation /
  2. Google Product Feed - Feed item caching

Google Product Feed – Feed item caching

Why “Feed item caching”?

The aim of the Google Product Feed plugin is to produce an up-to-date, accurate feed of all of your eligible products. In order to achieve this, the plugin currently generates the feed on-demand as it is requested. This avoids any issues cause by out of date information being sent in the feed. The plugin also generates the feed information using all of WooCommerce / WordPress’ APIs. This allows other extensions, or custom code to make any amendments they make to your product make-up ensuring that the information in the feed matches that in your store.

The main downside to this approach is that when generating a feed your server has to load each product individually, process it and output the feed content. On lower capacity hosting, or on stores with large inventories, this simply isn’t practical, and a full feed for all products can’t be generated in one pass. Historically, the workaround for this involved creating multiple partial feeds, each containing a chunk of the full product set.

This is more complex to set up, and manage, and can have issues where products could appear in multiple different chunks. Recent versions of the plugin introduce a new approach to solving this issue – “feed item caching”.

How feed item caching works

↑ Back to top

At its simplest, whenever the feed output is generated for a product in the feed, a copy is also stored in a cache. This pre-rendered output can then be used instead of calculating the full product information, invoking plugins etc. allowing the feed output to be created quickly, and with relatively low server overhead. The plugin also contains a number of background jobs that will populate the cache for all products automatically in the background.

Whenever anything changes that might make the cached information incorrect, such as updating a product, category, or the plugin settings, the cache for any affected products is dropped, and background jobs are queued to re-build them automatically, with the aim that no incorrect information is output, and cached data is available when required.

The aim is to allow the vast majority of stores to use full feeds without having to resort to chunked, or partial feeds.

Things to be aware of

↑ Back to top

The background job processing requires that WordPress cron is running on your site, this may not be the case if your site is being IP restrictions, or maintenance mode type plugins. If that is the case, the background jobs will not run, but the cache will still be used, and populated when a feed is requested.

When you first enable caching, or if you change the core plugin settings, then a rebuild will be triggered for all products. The background processing carries this out in small chunks to minimise overhead on your hosting, however you may see usage rise until the cache has been generated.

How to enable feed item caching

↑ Back to top

If you are having problems generating a full feed for your site, or you just want to test the new feature then you can enable it by creating a file in your WordPress plugins folder called enable-gpf-render-cache.php. The contents of this file should be as below:

<?php
/*
Plugin Name: Enable WooCommerce GPF feed item cache.
Plugin URI: http://docs.woothemes.com/document/google-product-feed/
Description: Enables feed item caching in the Google Product Feed extension.
Version: 1.0
Author: Lee Willis
Author URI: https://plugins.leewillis.co.uk/
*/
add_filter( 'woocommerce_gpf_render_cache_enabled', '__return_true' );

Once the file has been installed, activate the plugin from your WordPress admin panel

Note: This code must be installed as a plugin, not in your theme’s functions.php file. The feed item cache feature requires the following, and cannot be activated on earlier versions:

  • WordPress v4.5.0 or higher
  • WooCommerce v3.0.0 or higher
  • WooCommerce Google Product Feed plugin v7.1.0 or higher

How to monitor cache status

↑ Back to top

If caching is enabled, then the current cache status will be shown on the plugin settings page. This will show you the number of products that have their output cached, the total number of products that are eligible for inclusion in the feed.

The panel also includes options for refreshing the stats, and for rebuilding the cache for all products – although this shouldn’t be necessary.

Questions / problems

↑ Back to top

If you have any problems activating, or using the feed item cache, then please get in touch with support.