chesio / bc-cache

Simple full page cache plugin for WordPress inspired by Cachify
The Unlicense
9 stars 0 forks source link

Make directory size calculations consistent #35

Closed chesio closed 5 years ago

chesio commented 5 years ago

Right now there are two methods that calculate cache size: Core::getDirectorySize() calculates the size including directories while Core::getCacheSizes() only reports file sizes.

The difference can be seen when running bc-cache size command in WP-CLI (it uses the first method) and comparing the output to what Cache Viewer reports (it uses the second method).

I'm not sure in the moment what the better approach is.

chesio commented 5 years ago

I think matching what du -sb reports is the way to go.

chesio commented 5 years ago

It's actually a little bit more complicated: Core::getCacheSizes() only reports file sizes of files that are expected to be there and depends on bc-cache/filter:request-variants filter to correctly return all variants, while Core::getDirectorySize() does not care and counts all files that are present in root cache directory and its subdirectories.

So both methods can/should report different overall cache sizes if:

  1. There are multiple variants, but they are not correctly returned via bc-cache/filter:request-variants filter.
  2. Request variants have changed and bc-cache/filter:request-variants filter has been adjusted, but cache have not been flushed yet - in such case there might be stray files ignored by Core::getCacheSizes().