Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache is not getting Updated after post publish #14

Open
mksamadnet opened this issue Jun 2, 2017 · 3 comments
Open

Cache is not getting Updated after post publish #14

mksamadnet opened this issue Jun 2, 2017 · 3 comments

Comments

@mksamadnet
Copy link

mksamadnet commented Jun 2, 2017

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
Copy link
Owner

airesvsg commented Jun 2, 2017

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

@mksamadnet
Copy link
Author

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
Copy link

thefrosty commented Jan 10, 2018

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants