Add-ons /

Cache

Developer documentation for the Ajax Load More Cache add-on.


Auto-Generate Cache

The Ajax Load More cache can be auto-generated by populating the alm_cache_array filter with an array of cache URLs and IDs.

The alm_cache_array filter lets Ajax Load More know which cache instances should be auto-generated when the build is initiated.

Parameters

The following array parameters are available for each cache item. Note: url and id are required fields.

url The URL to the page holding the cache instance.Required
id The unique cache_id of the ALM instance.Required
max The maximum number of cache pages to create per item.

Before the cache is auto-generated, the current Ajax Load More cache is emptied – this means even cache instances that are not set to be auto-generated will be cleared.

Note: The Ajax Load More cache is not built on its own, it requires you to initiate the build process from the WordPress admin.

Building the Cache

To start the cache build process, you’ll need to visit the Ajax Load More Cache page in your WordPress admin and click the Generate Cache button in the sidebar.

Auto-generate Ajax Load More Cache admin screen

Once initiated, you will be redirected to a new page (as shown above) where you can track the cache progress and status.

Note: If you exit the page while auto-generating the cache, the process will stop where you exited.


Filter Hooks

The following filter hooks are available when using this add-on:

 alm_cache_created

The alm_cache_created action is triggered after a cache file has been created.

alm_cache_deleted

The alm_cache_deleted action is triggered after an individual cache file or the entire ALM cache has been deleted.

alm_cache_path

The alm_cache_path filter can be used to update the absolute server path of the Ajax Load More Cache – this path is used when writing and saving files to your server.

The following snippet will adjust the default cache path to a /cache/ folder in the current theme directory.

NOTE: When filtering the cache location you must update both alm_cache_path and alm_cache_url hooks.

alm_cache_url

The alm_cache_url filter can be used to update the URL path to the Ajax Load More Cache – this URL is used when rendering the cached content of an Ajax Load More query.

The following snippet will adjust the default cache URL to a /cache/ folder in the current theme directory.

NOTE: When filtering the cache URL you must update both alm_cache_path and alm_cache_url hooks.

alm_clear_cache

The alm_clear_cache action can be used by authenticated users to clear the full Ajax Load More cache or by a specific cache ID.


Dynamic Cache ID

In some instances, you will be required need to create the cache_id dynamically. In the case of taxonomy archives (category.php, tag.php) or when filtering by a querystring the cache_id should be generated on the fly to avoid issues with cache duplication.

Archives

The following example uses the current taxonomy and slug to create a unique cache_id for an archive template.

Querystring

The following example parses the URL querystring of a WooCommerce shop to create a unique cache_id for sorted products.

Template Variables

The following template variables can be injected into a cache shortcode to dynamically set the cache_id.

%post_id% The current post ID as a string.
%post_slug% The current post slug as a string.

« Back to Add-ons