Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 799 forks source link

[Super Cache] Preventing cache clear for a post does not prevent home page cache from being invalidated #28668

Closed dilirity closed 8 months ago

dilirity commented 1 year ago

Impacted plugin

Super Cache

Quick summary

Home page cache is invalidated when preventing cache clear using this filter.

Steps to reproduce

  1. Install version 1.9.3 of super cache;
  2. Enable caching (simple);
  3. Open a few pages and make sure cache files are created (cache folder /wp-content/cache/supercache/sitedomain.com/)
  4. Add the following snippet to the theme's functions.php:
    
    // This snippet will register a post type `myprefix_movies` and when adding/updating
    // a post from that post type, cache clear will be prevented.

function create_posttype() {

register_post_type(
    'myprefix_movies',
    // CPT Options.
    array(
        'labels'             => array(
            'name'          => __( 'Movies' ),
            'singular_name' => __( 'Movie' ),
        ),
        'public'             => true,
        'publicly_queryable' => false,
        'show_in_rest'       => true,
    )
);

}

// Hooking up our function to theme setup. add_action( 'init', 'create_posttype' );

add_filter( 'wp_super_cache_clear_post_cache', function ( $clear, $post ) { if ( 'myprefix_movies' === $post->post_type ) { return false; }

return $clear;

}, 10, 2 );


5. Add a post to the post type.
6. Check cache - it shouldn't be cleared, but the home page cache file will have `.needs-rebuild` at the end.

### A clear and concise description of what you expected to happen.

The filter should prevent any cache clear as well as invalidation of the cache.

### What actually happened

Cache was invalidated when above snippet was used and a post was added/updated.

### Impact

Some (< 50%)

### Available workarounds?

No but the platform is still usable

### Platform (Simple and/or Atomic)

Simple, Self-hosted

### Logs or notes

The filter works as expected, there's just a side effect related to the usage (I think).
github-actions[bot] commented 1 year ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.