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 and clearing #164

Closed coreykn closed 4 years ago

coreykn commented 4 years ago

Add Cache_Enabler_Disk::get_site_objects() to get the file system objects of a specific site. In most cases getting the site objects is as simple as getting the directory objects in the site directory, however, it needs to be filtered if the main site in a subdirectory network. This is because all other sites objects are stored in the main site directory too. This will fix the edge case of clearing the complete network cache when clearing the main site in a subdirectory network installed in a subdirectory. This will also fix getting the cache size for the main site in a subdirectory network (completing what was mentioned in PR #147).

Update Cache_Enabler::clear_site_cache_by_blog_id() to work for both single and multisites to allow the site cache of a single site to be cleared with this method. This can be done by using 1, which is returned when using get_current_blog_id() in a single site installation. Use Cache_Enabler_Disk::get_site_objects() to get the page(s) that need to be cleared. When deleting the cache size transient in a multisite installation switch to the blog ID provided to always ensure the correct transient is deleted. This fixes the case where the cache size transient of the main site would always be deleted when clearing the site cache through WP-CLI, regardless of the site(s) cleared.

Update Cache_Enabler::clear_complete_cache() to delete all cache size transients instead of only the main site. This fixes the issue where the cache size transient was not being deleted for all other sites when clearing the network cache.

Update Cache_Enabler::get_cache_size_transient_name() to not include the blog ID in the name as this is actually not required as the transient will be stored in the applicable site options table. Removing it prevents having to update methods to allow the blog ID to be included when this is called in Cache_Enabler::clear_complete_cache().

Update Cache_Enabler_Disk::clear_cache() to check if the directory exists before trying to clear it.

Update returned success message for multisites when clearing the complete cache with WP-CLI. Show the network has been cleared regardless if network activated because the entire network is actually cleared either way.

Remove the is_file() check from Cache_Enabler_Disk::cache_file_dir_path() because with the updates made to Cache_Enabler::clear_site_cache_by_blog_id() it will be triggered in nearly all cases when the site cache is cleared. I have been unable to identify what the purpose of this was for because the cache will not be delivered if the file is not readable (if two files were concatenated when getting the cache that file would not exist or be readable).