Last updated on

Fragment Caching is similar to Object Caching, in that it assists in improving performance by reducing the total number of database queries required to generate pages for many users. This works by freeing up MySQL server resources taken by serving repeated queries returning the same data each time, so that it has more power to handle real dynamic data.

Shared Server

In shared hosting platforms, you may only be able to cache files to a disk. In such cases, there is only one option available for Object Caching unless your hosting provider has a method listed under VPS / Dedicated Server or Multiple Servers available.

Disk

Disk-based caching stores the Objects to a folder within wp-content/cache as a file or set of files. Disk-based object caching is generally not recommended unless you are caching a small number of objects that are not likely to change often.

Caveats

VPS / Dedicated Server

Alternative PHP Cache (APC / APCu)

APC refers to Alternative PHP Cache which provides in-memory Opcode caching and a key-value store for looking up cached items. This is largely deprecated in favor of modern Opcode Caching mechanisms, as APC is not supported in the PHP 7.x branch.

APCu is similar to APC, though in order to support modern variants of PHP it is stripped of Opcode Caching and only provides the in-memory key-value store mechanisms. When paired with modern Opcode Caching mechanisms it can provide the functionality originally provided by APC, though it should only be used when you require having a limited cache size.

APC/APCu is not stable when a lot of memory allocated. In cases where you are caching a small amount of data, APC/APCu may be the ideal method for single-instance hosting platforms such as WordPress VPS or Dedicated hosting.

eAccelerator

eAccelerator is an in-memory Opcode caching solution that supports the PHP 4.x and 5.x major versions. This is largely deprecated in favor of modern Opcode Caching mechanisms, as eAccelerator is not supported in the PHP 7.x branch.

XCache

XCache is an in-memory Opcode caching solution that supports up to the PHP 5.6 release. This is largely deprecated in favor of modern Opcode Caching mechanisms, as XCache is not supported in the PHP 7.x branch.

WinCache (Recommended for Windows-based Environments)

WinCache is an extension for Microsoft IIS which provides in-memory Opcode caching and currently supports up to IIS 10 as of 04/30/2019. Check the official Microsoft product page for the latest information.

Caveats

Multiple Servers

If you have multiple hosting plans where one plan has root-level access, or if your hosting provider offers addons or bundles providing one of the following solutions, you may offload your in-memory caching to another server. This allows you to separate your actual site and caching solution between multiple servers to compliment each other, and allows for easier scaling to serve many users.

Memcached

Memcached is a high-performance, distributed memory object caching system meant to speed up dynamic web applications by alleviating database load. It provides an in-memory key-value store for small chunks of arbitrary data (strings, objects) from the results of database calls, API calls, or page rendering.

Memcached is ideal for relatively small and static data, and as a result may be more efficient than Redis. It is also multithreaded, which may be a benefit when using a VPS or Dedicated Server with a large resource pool.

Frequently Asked Questions

Enabling Fragment Caching didn’t improve my performance

Fragment Caching can help when there is a lot of dynamic content that Object/Database caching can’t resolve, though it requires a developer to tag content in pages. If you do not tag your page fragments, enabling Fragment Caching will have no effect.

W3 Total Cache

You haven't seen fast until you've tried PRO

   Full Site CDN + Additional Caching Options
   Advanced Caching Statistics, Purge Logs and More

Everything you need to scale your WordPress Website and improve your PageSpeed.

2 thoughts on “Choosing a Fragment Caching Method for W3 Total Cache

  1. I’m trying to implement Fragment caching to achieve the following.
    cache all pages/links unless stated otherwise.
    don’t cache the shopping basket (since it is on every page)

    I can cache pages and preload them.
    i have certain woocommerce categories i don’t want to be cached.
    As of now it’s not clear to me if i’m using the right codes and if that works as wanted.

    Fragment cache doesn’t seem todo or works differently or lacks documentation since all i could find online was the below.

    inside wp-config.php i added the following.
    define(‘W3TC_DYNAMIC_SECURITY’, ‘Donnotcachethis’);

    Inside my header.php i placed the below code for testing purposes.
    <!–mfunc –>

    <!–/mfunc –>

    This shows the current time on first page request, but same time keeps getting displayed on every f5 i use.

    Both Page cache and Fragment Cache use redis server.
    Late initialisation is active

    And for the rest there is no information anywhere about this topic!

Leave a Reply

Your email address will not be published. Required fields are marked *