Skip to content

Instantly share code, notes, and snippets.

@nawawi
Created August 16, 2024 14:50
Show Gist options
  • Save nawawi/25a6f666adbc338b776d1b93a59415b5 to your computer and use it in GitHub Desktop.
Save nawawi/25a6f666adbc338b776d1b93a59415b5 to your computer and use it in GitHub Desktop.
<?php
add_action('docketcache/init', function($docket_cache_instance) {
$docket_cache = $docket_cache_instance;
// Flush cache
add_action('docket_cache_control_flush_cache', function() use($docket_cache) {
$result = $docket_cache->flush_cache(true);
$docket_cache->co()->lookup_set('occacheflushed', $result);
do_action('docketcache/action/flush/objectcache', $result);
});
// Enable dropin
add_action('docket_cache_control_enable_dropin', function() use($docket_cache) {
$result = $docket_cache->cx()->install(true);
do_action('docketcache/action/enable/objectcache', $result);
});
// Disable dropin
add_action('docket_cache_control_disable_dropin', function() use($docket_cache) {
$result = $docket_cache->cx()->uninstall();
do_action('docketcache/action/disable/objectcache', $result);
});
// Update dropin
add_action('docket_cache_control_update_dropin', function() use($docket_cache) {
$result = $docket_cache->cx()->install(true);
do_action('docketcache/action/update/objectcache', $result);
});
// Flush menu cache
add_action('docket_cache_control_flush_menucache', function() use($docket_cache) {
$result = 0;
$ok = false;
if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
$result = wp_cache_flush_group('docketcache-menu');
$docket_cache->co()->lookup_set('menucacheflushed', $result);
$ok = true;
}
do_action('docketcache/action/flush/file/menucache', $ok, $result);
});
// Flush mocache
add_action('docket_cache_control_flush_mocache', function() use($docket_cache) {
$result = 0;
$ok = false;
if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
$result = wp_cache_flush_group('docketcache-mo');
$docket_cache->pt->co()->lookup_set('mocacheflushed', $result);
$ok = true;
}
do_action('docketcache/action/flush/file/mocache', $ok, $result);
});
// Flush precache
add_action('docket_cache_control_flush_precache', function() use($docket_cache) {
$result = 0;
$ok = false;
if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
$result = wp_cache_flush_group('docketcache-precache');
$docket_cache->pt->co()->lookup_set('ocprecacheflushed', $result);
$ok = true;
}
do_action('docketcache/action/flush/file/ocprecache', $ok, $result);
});
// Flush transient
add_action('docket_cache_control_flush_transient', function() use($docket_cache) {
$result = 0;
$ok = false;
if (\function_exists('wp_cache_flush_group') && method_exists('WP_Object_Cache', 'dc_remove_group')) {
$result = wp_cache_flush_group(['transient', 'site-transient']);
$docket_cache->pt->co()->lookup_set('transientflushed', $result);
$ok = true;
}
do_action('docketcache/action/flush/file/transient', $ok, $result);
});
// Run optimizedb
add_action('docket_cache_control_optimizedb', function() use($docket_cache) {
$result = (new Nawawi\DocketCache\Event($docket_cache))->optimizedb();
do_action('docketcache/action/event/optimizedb', $result);
});
// Run install runtime code
add_action('docket_cache_control_runtime_install', function() use($docket_cache) {
$result = Nawawi\DocketCache\WpConfig::runtime_install();
do_action('docketcache/action/updatewpconfig', $result);
});
// Run uninstall runtime code
add_action('docket_cache_control_runtime_uninstall', function() use($docket_cache) {
$result = Nawawi\DocketCache\WpConfig::runtime_remove();
do_action('docketcache/action/updatewpconfig', $result);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment