- Timestamp:
- 10/13/2026 10:00:51 AM (13 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
optimazz/trunk/includes/Modules/Cache/Storage/DiskStorage.php
r3723128 r3743505 29 29 30 30 public function purge_all() { 31 if ( is_multisite() ) { 32 \Optimazz_Cache_Engine::purge_site_dir( self::site_dir() ); // This site only. 33 return; 34 } 31 35 \Optimazz_Cache_Engine::purge_all(); 36 } 37 38 /** 39 * Cache folder of the current network site. 40 * 41 * @return string 42 */ 43 private static function site_dir() { 44 $site = get_site(); 45 return \Optimazz_Cache_Engine::site_dir( $site ? $site->domain : (string) wp_parse_url( home_url(), PHP_URL_HOST ), $site ? $site->path : '/' ); 32 46 } 33 47 … … 39 53 public function stats() { 40 54 $root = \Optimazz_Cache_Engine::cache_root(); 55 $skip = array(); 56 if ( is_multisite() ) { 57 // Count this site's folder only, not other sites nested inside it. 58 $root = self::site_dir(); 59 $skip = array_values( array_diff( \Optimazz_Cache_Engine::site_roots(), array( $root ) ) ); 60 } 41 61 if ( ! is_dir( $root ) ) { 42 62 return array( … … 49 69 $files = 0; 50 70 $bytes = 0; 51 // A page (one URL) is stored as several variants in its own folder —52 // desktop/mobile, http/https, query strings. "Cached pages" counts the53 // pages, so it matches what the preloader reports; 'files' is kept for54 // the rawvariant count.71 // A page (one URL) is stored as several variants — desktop/mobile, 72 // http/https, logged-in buckets. "Cached pages" counts the pages, so it 73 // matches what the preloader reports; 'files' is kept for the raw 74 // variant count. 55 75 $dirs = array(); 56 76 $it = new \RecursiveIteratorIterator( 57 new \RecursiveDirectoryIterator( $root, \FilesystemIterator::SKIP_DOTS ) 77 new \RecursiveCallbackFilterIterator( 78 new \RecursiveDirectoryIterator( $root, \FilesystemIterator::SKIP_DOTS ), 79 static function ( $file ) use ( $skip ) { 80 // Skip other network sites' folders (empty on a single site). 81 return ! ( $file->isDir() && in_array( rtrim( $file->getPathname(), '/' ) . '/', $skip, true ) ); 82 } 83 ) 58 84 ); 59 85 foreach ( $it as $file ) { … … 66 92 ++$files; 67 93 $bytes += (int) $file->getSize(); 68 $dirs[ $file->getPath() ] = true; 94 // File name: {scheme}-{device}-{user}[-{query}].html. One page = its 95 // folder. At the site root the query part counts too, because plain 96 // permalinks (?page_id=5) keep every page there; elsewhere query 97 // variants (e.g. /shop/?orderby=price) are the same page. 98 $parts = explode( '-', $file->getBasename( '.html' ), 4 ); 99 $at_root = false === strpos( trim( substr( $file->getPath(), strlen( $root ) ), '/' ), '/' ); 100 $dirs[ $file->getPath() . '|' . ( $at_root && isset( $parts[3] ) ? $parts[3] : '' ) ] = true; 69 101 } 70 102 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)