Filter uncanny-automator

automator_cache_expiry

Filters the cache expiration time for Automator-generated data, allowing customization of how long cached items remain valid.

add_filter( 'automator_cache_expiry', $callback, 10, 1 );

Description

Filters the cache expiration time for automator data. Modify this value to control how long cached data remains valid. The default is 30 minutes. This hook fires when the cache expiration duration is being determined.


Usage

add_filter( 'automator_cache_expiry', 'your_function_name', 10, 1 );

Parameters

$expiry (mixed)
This parameter is the default cache expiration time in seconds.

Return Value

The filtered value.


Examples

/**
 * Filter to adjust the default cache expiry for automator items.
 *
 * This example increases the default cache expiry from 30 minutes to 1 hour
 * for automator cache items, unless a specific configuration is set otherwise.
 *
 * @param int|false $expiry The current cache expiry in seconds.
 * @return int The adjusted cache expiry in seconds.
 */
add_filter( 'automator_cache_expiry', function( $expiry ) {

	// Check if the expiry is already set to false (meaning cache is disabled)
	// or if it's not an integer (unexpected value).
	if ( false === $expiry || ! is_int( $expiry ) ) {
		return $expiry; // Return original value if invalid.
	}

	// Define a custom expiry duration in minutes.
	$custom_expiry_minutes = 60; // 1 hour

	// Optionally, you might check for a specific option or constant to override.
	// For demonstration, we'll just increase it.
	$new_expiry = $custom_expiry_minutes * MINUTE_IN_SECONDS;

	// Return the new expiry time.
	return $new_expiry;

}, 10, 1 );

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:103

0
		);

		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(


Scroll to Top