Plugin Directory


Ignore:
Timestamp:
10/13/2026 10:00:51 AM (13 days ago)
Author:
shiponkarmakar
Message:

Release v1.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • optimazz/trunk/includes/Modules/Cache/Storage/DiskStorage.php

    r3723128 r3743505  
    2929
    3030        public function purge_all() {
     31                if ( is_multisite() ) {
     32                        \Optimazz_Cache_Engine::purge_site_dir( self::site_dir() ); // This site only.
     33                        return;
     34                }
    3135                \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 : '/' );
    3246        }
    3347
    … …  
    3953        public function stats() {
    4054                $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                }
    4161                if ( ! is_dir( $root ) ) {
    4262                        return array(
    … …  
    4969                $files = 0;
    5070                $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 the
    53                 // pages, so it matches what the preloader reports; 'files' is kept for
    54                 // the raw variant 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.
    5575                $dirs  = array();
    5676                $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                        )
    5884                );
    5985                foreach ( $it as $file ) {
    … …  
    6692                                ++$files;
    6793                                $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;
    69101                        }
    70102                }
Note: See TracChangeset for help on using the changeset viewer.