Advanced Questions for WP Cloudflare Super Page Cache

  1. Can I configure this plugin using PHP constants?

    Yes, you can use the following PHP constants:

    • SWCFPC_CACHE_BUSTER, cache buster name. Default: swcfpc
    • SWCFPC_CF_API_ZONE_ID, Cloudflare zone ID
    • SWCFPC_CF_API_KEY, API Key to use
    • SWCFPC_CF_API_EMAIL, Cloudflare email to use (API Key authentication mode)
    • SWCFPC_CF_API_TOKEN, API Token to use
    • SWCFPC_PRELOADER_MAX_POST_NUMBER, max pages to preload. Default: 1000
    • SWCFPC_CF_WOKER_ENABLED, true or false
    • SWCFPC_CF_WOKER_ID, CF Worker ID
    • SWCFPC_CF_WOKER_ROUTE_ID, route ID
    • SWCFPC_CF_WOKER_FULL_PATH, the full path to worker template to use
    • SWCFPC_CURL_TIMEOUT, timeout in seconds for cURL calls. Default: 10
    • SWCFPC_PURGE_CACHE_LOCK_SECONDS, time in seconds for cache purge lock. Default: 10
    • SWCFPC_PURGE_CACHE_CRON_INTERVAL, the time interval in seconds for the purge cache cronjob. Default: 10
    • SWCFPC_HOME_PAGE_SHOWS_POSTS, if the front page a.k.a. the home page of the website showing the latest posts. Default: true (bool)
  2. What hooks can I use?

    Actions:

    • swcfpc_purge_all, no arguments. Fired when whole caches are purged.
    • swcfpc_purge_urls, no arguments. Fired when caches for specific URLs are purged.
    • swcfpc_cf_purge_whole_cache_before, no arguments. Fired before purge the Cloudflare whole cache.
    • swcfpc_cf_purge_whole_cache_after, no arguments. Fired after the Cloudflare whole cache is purged.
    • swcfpc_cf_purge_cache_by_urls_before, no arguments. Fired before purge the Cloudflare cache for specific URLs only.
    • swcfpc_cf_purge_cache_by_urls_after, no arguments. Fired after the Cloudflare cache for specific URLs only is purged.

    Filters:

    • swcfpc_cache_bypass, one argument. Return true to bypass the cache.
    • swcfpc_post_related_url_init, $listofurls (array), $postId. Fired when creating the initial array that holds the list of related URLs to be purged when a post is updated. Show return array of full URLs (e.g. https://example.com/some-example/) that you want to include in the related purge list.
  3. Can I use my own worker code along with the default worker code this plugin uses?

    Unfortunately, Cloudflare allows one worker per route. So, as long as our worker is set up in the main route, you cannot use your own worker code in the same route. But you can take advantage of SWCFPC_CF_WOKER_FULL_PATH PHP constant to provide the full path of your own custom JavaScript file.
    In this way, you can take a look at inside the plugin's /assets/js/worker_template.js path and see the Worker code we are using by default. Then you can copy that worker template file to your computer and extend it to add more features and conditions that you might need in your project. Once you are done with your Worker code, you can simply point your custom Worker template JavaScript file inside wp-config.php using the SWCFPC_CF_WOKER_FULL_PATH PHP constant and the plugin will use your Worker file to create the worker in your website route instead of using the default Worker code. Here is an example of how to use the PHP constant inside your wp-config.php. Please make sure you provide the absolute path of your custom Worker file.

    define('SWCFPC_CF_WOKER_FULL_PATH', '/home/some-site/public/wp-content/themes/your-theme/assets/js/my-custom-cf-worker.js');
    	

    Please note that for 99.999% of users the default Worker code will work perfectly if they choose to use the Worker mode over the Page Rule mode. This option will be provided only for Super Advanced Knowledgeable Users who know exactly what they are doing and which will lead to what. General users should avoid tinkering with the Worker Code as this might break your website if you don't know what you are doing.

  4. Can I purge the cache programmatically?

    Yes. To purge the whole cache use the following PHP command:

    do_action("swcfpc_purge_cache");
    	

    To purge the cache for a subset of URLs use the following PHP command:

    do_action("swcfpc_purge_cache", array("https://example.com/some-page/", "https://example.com/other-page/"));
    	
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us