• Resolved John Webber

    (@bilion)


    Hello, Powered Cache Support Team,

    I’m developing a performance improving plugin and have a specific caching requirement.

    I need pages and posts not to be cached on first open, after they are created or edited.

    I need to examine the page with all the JS and CSS implemented, then edit the HTML before it can be cached. So, the page should be cached on the second visit.

    Is there a built-in feature or specific hook in Powered Cache that supports this functionality, and can be controlled through PHP?

    I am considering a custom implementation using WordPress hooks. Here’s a brief overview of my approach:

    // Function to update a custom field when a post or page is saved
    
    function update_last_modified_meta($post_id) {
    
        update_post_meta($post_id, '_last_modified_time', current_time('mysql'));
    
    }
    
    add_action('save_post', 'update_last_modified_meta');
    
    // Function to control caching based on the last modified time
    
    function custom_per_page_cache_control() {
    
        if (is_single() || is_page()) {
    
            global $post;
    
            $stored_last_modified = get_post_meta($post->ID, '_last_modified_time', true);
    
            if ($post->post_modified !== $stored_last_modified) {
    
                // Send headers to prevent caching
    
                header("Cache-Control: no-cache, must-revalidate, max-age=0");
    
                header("Pragma: no-cache");
    
                header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
    
                update_post_meta($post->ID, '_last_modified_time', $post->post_modified);
    
            }
    
        }
    
    }
    
    add_action('template_redirect', 'custom_per_page_cache_control');

    Is this approach is compatible with your plugin? Is there a solution specific to your plugin?

    Any recommendations or best practices for implementing this would be greatly appreciated.

    Thank you,

    Jovan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mustafa Uysal

    (@m_uysl)

    Hi @bilion,

    Is there a built-in feature or specific hook in Powered Cache that supports this functionality, and can be controlled through PHP?

    You can take a look powered_cache_page_cache_enable hook to control caching behavior programmatically.

    Is this approach is compatible with your plugin? Is there a solution specific to your plugin?

    Yes, this approach is compatible with the Powered Cache plugin. It will require some customization, but the plugin offers enough flexibility to accommodate this solution.

    Any recommendations or best practices for implementing this would be greatly appreciated.

    It might be better if you could define DONOTCACHEPAGE constant with the headers.

    I hope this helps. You can use hook docs to learn more about filters/actions.

    Thread Starter John Webber

    (@bilion)

    Hi, Mustafa

    Yes, defining the DONOTCACHEPAGE constant was the solution I was looking for

    Thank you for your help

    Jovan

    Plugin Author Mustafa Uysal

    (@m_uysl)

    Hi @bilion,

    I’m glad to hear that it did the trick. Your positive experience means a lot to us. If you’re willing, I would really appreciate it if you could share your thoughts and experiences in a review.

    Your feedback helps us continue improving and supports the community too. Thank you for considering!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prevent Caching On First Open’ is closed to new replies.