Cache
config/cache.php
The cache configuration file defines which cache drivers are active and what flush rules fire on WordPress events.
drivers
Section titled “drivers”List of cache driver classes to use. Each driver implements CacheDriverContract (flushPost, flushUrl, flushAll).
Built-in drivers
Section titled “Built-in drivers”W3TCDriver — flushes via W3 Total Cache (w3tc_flush_post, w3tc_flush_url, w3tc_flush_all). No-ops gracefully if W3TC is not active.
TransientDriver — deletes WordPress transients by prefix, then calls wp_cache_flush(). Construct with a prefix:
new TransientDriver('my_prefix')flushPost and flushUrl are no-ops by default — subclass and override if your transients are keyed by post ID or URL.
Custom drivers
Section titled “Custom drivers”Implement App\Lib\Contracts\CacheDriverContract:
use App\Lib\Contracts\CacheDriverContract;
class MyDriver implements CacheDriverContract{ public function flushPost(int $postId): void {} public function flushUrl(string $url): void {} public function flushAll(): void {}}Then add the class to drivers:
return [ 'drivers' => [ MyDriver::class, // or pass an already-constructed instance new TransientDriver('my_prefix'), ],];Each rule maps a WordPress event (trigger) to one or more flush targets (flush). An optional filters key narrows which events fire the rule.
triggers
Section titled “triggers”| Trigger | WordPress hook | filters keys |
|---|---|---|
post_saved | save_post / save_post_{post_type} | post_type |
post_deleted | before_delete_post | post_type |
post_trashed | trashed_post | post_type |
term_saved | edited_{taxonomy}, created_{taxonomy} | taxonomy (required) |
term_deleted | pre_delete_term | taxonomy (required) |
options_saved | acf/save_post (options page only) | — |
Autosaves and revisions are automatically skipped for post_saved.
flush targets
Section titled “flush targets”Each entry in flush is either a string shorthand or an array selector.
String shorthands
| Value | What flushes |
|---|---|
'self' | The saved/deleted post itself (flushPost($postId)) |
'all' | Everything (flushAll()) |
'term_archive' | The term’s archive URL (flushUrl(get_term_link($termId))) |
Array selectors
['template' => 'news'] // all pages using templates/news.php['template' => 'blog.php'] // pass full filename to skip auto-prefix['url' => '/some/path'] // absolute or relative URL['url' => 'https://...'] // full URL['post_id' => 42] // specific post by ID['page_slug' => 'contact'] // page looked up via get_page_by_path()Examples
Section titled “Examples”return [ 'drivers' => [ W3TCDriver::class, ], 'rules' => [ // flush the post itself + the news listing page when a post is saved [ 'trigger' => 'post_saved', 'filters' => ['post_type' => PostTypeConstant::POST], 'flush' => [ 'self', ['template' => 'news'], ], ],
// flush a specific URL when any page is saved [ 'trigger' => 'post_saved', 'filters' => ['post_type' => 'page'], 'flush' => [ 'self', ['url' => '/sitemap.xml'], ], ],
// flush the term's archive when a category is edited or created [ 'trigger' => 'term_saved', 'filters' => ['taxonomy' => TaxonomyConstant::CATEGORY], 'flush' => ['term_archive'], ],
// flush everything when ACF options are saved [ 'trigger' => 'options_saved', 'flush' => ['all'], ], ],];
