Filter
uncanny-automator
automator_cache_long_expiry
Filters the cache expiry duration for long-term storage, allowing customization of how long data persists.
add_filter( 'automator_cache_long_expiry', $callback, 10, 1 );
Description
Allows modification of the long cache expiry duration (default 24 hours). Developers can use this filter to set a custom expiry time for cache entries that are intended for longer storage, potentially improving performance for frequently accessed but less frequently updated data. The value should be an integer representing seconds.
Usage
add_filter( 'automator_cache_long_expiry', 'your_function_name', 10, 1 );
Parameters
-
$expiry(mixed) - This parameter controls the duration, in seconds, for which long-term cache entries will remain valid.
Return Value
The filtered value.
Examples
<?php
/**
* Filters the long expiry time for the Automator cache.
*
* This example extends the default 24-hour long expiry to 48 hours for specific post types.
*
* @param int $expiry The current expiry time in seconds.
* @return int The modified expiry time in seconds.
*/
add_filter(
'automator_cache_long_expiry',
function( $expiry ) {
// Get the current post type if we are within the context of a post operation.
// This assumes the filter is called during a process where 'get_post_type()' is valid.
$current_post_type = get_post_type();
// Define post types that should have an extended cache expiry.
$extended_cache_post_types = array( 'post', 'page', 'custom_post_type' );
// If the current post type is one of those that should have extended caching,
// double the default long expiry time.
if ( in_array( $current_post_type, $extended_cache_post_types, true ) ) {
// Extend the expiry to 48 hours (2 days).
$expiry = 48 * HOUR_IN_SECONDS;
}
// Return the potentially modified expiry time.
return $expiry;
},
10, // Priority
1 // Accepted args
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/helpers/class-automator-cache-handler.php:106
if ( false === $this->is_cache_enabled() ) {
return;
}
$expiry = 30 * MINUTE_IN_SECONDS; // 5 mins.
$this->expires = apply_filters( 'automator_cache_expiry', $expiry );
$expiry = 1440 * MINUTE_IN_SECONDS; // 24 hours.
$this->long_expires = apply_filters( 'automator_cache_long_expiry', $expiry );
add_action(
'wp_after_insert_post',
array(
$this,
'maybe_clear_cache_for_posts',
),