Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality to flush the cache for a domain or any other batcache key #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xdancho
Copy link

@xdancho xdancho commented Dec 11, 2023

Flush keys can be used to change the cache key hash by adding an additional element to the $batcache->keys array. This can be used to flush the cache for any key that can have duplicates, e.g. host.
For example, one may want to invalidate the cache for a host/domain via mu-plugin on theme change.

Configuration:

  • Requires a global object cache group.
  • Add a key from $batcache->keys in $flush_keys array. For example:
$flush_keys = array( 'host' );

Note: Adding a key in $flush_keys will invalidate the entire batcache cache.

  • Call the flush method with args key and the value of that key. Example:
    If we want to flush the cache for a specific host/domain on theme change:
add_action ( 'switch_theme', function(){
    global $batcache;
    $batcache->flush( 'host', $_SERVER['HTTP_HOST'] );
} );

@aidvu aidvu self-assigned this Dec 13, 2023
@aidvu aidvu self-requested a review December 13, 2023 16:12
Copy link
Contributor

@aidvu aidvu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants