keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

update cache size transient handling #287

Closed coreykn closed 3 years ago

coreykn commented 3 years ago

Update Cache_Enabler::on_cache_created_cleared() to only call Cache_Enabler::get_cache_size() when the cache_enabler_cache_size transient does not exist and the changed cache size is positive (so when a cached page has been created). This will prevent calling this unnecessarily and way too often.

The issue was as soon as a page being cleared had an index count greater than 1, like if a paginated page had been cleared, it would delete the transient. The following call to Cache_Enabler::on_cache_created_cleared() would call Cache_Enabler::get_cache_size() because the cache size transient no longer exists (Cache_Enabler::on_cache_created_cleared() can be called several times during one cache clear query, like clearing the post cache after a post has been updated). The following calls may or may not do the same thing, which means it could use up a lot of resources in certain situations when going back and forth like this. It was not an issue for when the site cache was being cleared.

This updates what was added in PR #237 and updated in PR #269.