Please stop running wp_cache_flush() whenever posts are edited!
-
Hello, love this plugin, solved my problem and is very well done!
But your use of caching was completely destroying our server’s object cache! When you run
wp_cache_flush();
it completely empties the persistent object cache, which contains tons of other stuff like posts, terms and anything else inserted by other plugins.In some cases it can also clear the caches of OTHER SITES since many object caching plugins clear the whole cache (memcached/redis/apc) and not just the current site. Overall wp_cache_flush() should really only be used by caching plugins as a way to reset the server.
In this plugin’s case it’s even more disastrous because you run it whenever a post transitions status, which happens any time a new post is created and during it’s first save (auto-draft->draft). This is a big problem because it meant my whole cache was being demolished every minute or so as users acted on the site.
FIXING IT IS EASY
The good news is you can very easily fix the key problem by not running wp_cache_flush() at all! Based on my searching you only actually one one key in the cache, so you can just delete it directly if you want:
`
function cache_flush()
{
// make this optional?
// wp_cache_flush();
wp_cache_delete(‘xmlsf_get_archives’, ‘general’);
}
`
That fixed my issue completely, and having that single key get deleted all the time is no big deal.
—
Taking it to the next level you could add some more nuanced filtering so your cache_flush() only gets fired when the status transition involves a published post, since those are far less common and the only ones that affect sitemaps.
—
Thank you for fixing your version of the plugin so I can get your updates in the future without having to re-insert my patch ??
- The topic ‘Please stop running wp_cache_flush() whenever posts are edited!’ is closed to new replies.