The Plugin Cache is Growing Excessively

Managing the amount of cache generated

Occasionally on some websites there can be an unusual amount of cache generated. Understandably, a major concern is server disk space or load but this could also be an indicator that you are not benefitting as much as you should from the plugin in terms of increased page load.

Identifying abnormal amount of cache files.  It's normal for the plugin to generate some amount of cache files. The amount varies by website but a couple thousand files is not unusual. However if the number of files grows into tens of thousands or weighing close or more than a Gigabyte then you should probably investigate further to manage this issue.

How the plugin generates cache

The plugin will parse the HTML to find the CSS files and inline styles, and javascript files and inline scripts to combine. It will use a hash of the file names and contents of inline styles/scripts to generate an id for the cache file that it will create for that page. The plugin will use this id to locate the cache file later. If another page has the same combination of files and scripts as a previous page, the same id will be generated therefore the plugin will use that same cache file rather create a new one.

However, sometimes, on a particular page, some part of a file's url (most likely a query) keeps changing or some variable in an inline script keeps changing on each page load and so causes a different cache id to be generated in order to reflect these changes. To remedy the situation, we have to find the file/script that is changing and exclude it from the plugin.

Follow this procedure to find the file or script that keeps changing and exclude it from the plugin to prevent the cache from builging up excessively.

Procedure 5.2. Finding the file or script that keeps changing and causing excessive cache build up

  1. Find the offending page

    Check the HTML source of the page and note the filename(s) of the generated combined file(s). You're interested in the alphanumeric part from which the cache id will be determined. Reload the page and check if the file name changes. You probably want to do that with the top 5 most popular pages until you find the page with changing values.


    Be sure to disable any page caching plugins so any changes to the combined files will be detected immediately.

  2. Find where the changes are occurring

    When you find the offending page, temporarily disable the plugin then copy two instances of the HTML source in your favorite text editor and diff them to identify the changes. Only pay attention to the changes in the CSS or javascript filenames or block declarations. Changes in other HTML elements don't matter.

    HTML Diff in Text Editor

    HTML DIff in Text Editor

  3. Exclude the items with changing values

    You now exclude these items from the plugin so they don't cause a different cache id to be generated on each page load, generating an excess amount of cache. Use the settings on the Exclude Options tab to exclude the file or script that keeps changing. Read the Excluding files and declaration blocks article for more information on how to exclude items.

I can't find the items that are changing.  Alternatively, you can enable both settings on the Exclude Options tab called Exclude all internal STYLE/(SCRIPT) declarations. Most time the changes occur in some <script/> or <style/> element so this most likely will fix the issue if you can't find which items to exclude.

Exclude all inline codes

Exclude All Inline Codes