Skip to main content

Programmatically Purge and Preload Cache

Updated this week

FlyingPress provides simple PHP functions to purge and preload the cache directly from your code. This is useful for triggering cache operations during custom workflows, integrations, or admin tools.

These functions are available under the FlyingPress namespace.

Where to use

You can call these functions from:

  • A custom plugin

  • Theme code (e.g., functions.php)

  • Admin actions, cron jobs, or custom hooks

Make sure FlyingPress is active when calling these methods.

Purging Cache

Purge multiple URLs/pages

FlyingPress\Purge::purge_urls([
'https://example.com/page-1/',
'https://example.com/page-2/',
]);
  • $urls must be an array of absolute URLs

  • Each URL is purged individually

Purge all cached HTML pages

FlyingPress\Purge::purge_pages();
  • Clears all HTML page cache

  • Does not remove other cached files (e.g., fonts, static assets)

Purge everything (entire cache folder)

FlyingPress\Purge::purge_everything();
  • Deletes the entire FlyingPress cache folder

  • Recreates the cache directory after deletion

Preloading Cache

Preload a single URL/page

FlyingPress\Preload::preload_url('https://example.com/page/');

Preload multiple URLs/pages

FlyingPress\Preload::preload_urls([
'https://example.com/page-1/',
'https://example.com/page-2/',
]);
  • Each URL is queued and fetched for pre-caching

Preload all URLs

FlyingPress\Preload::preload_cache();
  • Uses FlyingPress’s default logic to determine which URLs to preload

  • Includes homepage, posts, pages, taxonomies, etc.

Notes

  • Preloading and purging are non-blocking—they can be safely used in hooks

  • Always pass fully qualified URLs (including protocol and trailing slash)

  • Use these functions only when needed to avoid unnecessary resource usage

Did this answer your question?