airesvsg / wp-rest-api-cache

Enable caching for WordPress REST API and increase speed of your application
http://wordpress.org/plugins/wp-rest-api-cache
247 stars 37 forks source link

Cache is not getting Updated after post publish #14

Open mksamadnet opened 7 years ago

mksamadnet commented 7 years ago

Hello,

I have installed WP REST API Cache and it is caching the rest api. However, the cache is not getting cleared after the new post publish

I have added the following code, but it is still not working

add_action( 'save_post', function( $post_id ) {
  if ( class_exists( 'WP_REST_Cache' ) ) {
    WP_REST_Cache::empty_cache();
  }
} );

Also, when I try to delete cache manually, the newest post is not appearing on the rest API. The API is getting updated only when I disable this plugin

Could you please let me know how I can fix this issue?

airesvsg commented 7 years ago

Hello @mksamadnet, What's the WordPress Version? Whats Plugins you are using? Thanks

mksamadnet commented 7 years ago

Hello @airesvsg, Thanks for the response! I'm using the latest WordPress Version 4.7.5 and using 10 WordPress plugins on the site which are listed below Add Shortcodes Actions And Filters Advanced Custom Fields Character Countdown Easy Heads Up Bar EWWW Image Optimizer Force Post Category Selection Jetpack by WordPress.com W3 Total Cache WP FCM WP REST API

I'm using the WordPress REST API as the data source for my mobile application. The data on the WordPress site or REST API is getting updated every 30 minutes or an hour. So, After each post update or new post added to the WordPress, I need the REST API cache to be cleared immediately. Hope you can help me on this issue!

thefrosty commented 6 years ago

Looks like the empty cache is called directly on the database, but the plugin is using the transients API to cache calls. If you're running any sort of object cache, transients are stored in memory and not in the database, so the empty_cache() method may not work as expected across installs.

A memcached plugin, for example, would make WordPress store transient values in fast memory instead of in the database. For this reason, transients should be used to store any data that is expected to expire, or which can expire at any time. -- codex

See issue #16 👍