Plugin Directory

Changeset 3358113


Ignore:
Timestamp:
09/08/2025 06:23:01 PM (7 months ago)
Author:
peterarends
Message:

Tagging version 1.1.1

Location:
simple-page-cache/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • simple-page-cache/trunk/readme.txt

    r3356518 r3358113  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.1.0
     6Stable tag: 1.1.1
    77License: GPLv2 or later
    88
     
    109109
    110110== Changelog ==
     111= 1.1.1 =
     112* **Bug fix**: Fixed 404 errors when browsing the website while logged in
     113* **Query parameter handling**: Plugin now properly checks for $_GET parameters and skips caching for requests with query strings
     114
    111115= 1.1.0 =
    112116* **Path-based cache structure**: Cache files now use `/host/path/index.html` structure for nginx direct serving
  • simple-page-cache/trunk/simple-page-cache.php

    r3356518 r3358113  
    33Plugin Name: Simple Page Cache
    44Description: Extremely simple page cache to disk for non-logged-in users. No expiry, only clears on manual action.
    5 Version: 1.1.0
     5Version: 1.1.1
    66Requires at least: 5.0
    77Tested up to: 6.8
     
    4040}
    4141
    42 // Only cache for non-logged-in users and only GET requests
     42// Only cache for non-logged-in users and only GET requests without query parameters
    4343function simplepagecache_should_cache()
    4444{
    45     return !is_user_logged_in() && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET';
     45    // Don't cache if user is logged in
     46    if (is_user_logged_in()) {
     47        return false;
     48    }
     49   
     50    // Don't cache if not a GET request
     51    if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') {
     52        return false;
     53    }
     54   
     55    // Don't cache if there are query parameters
     56    if (!empty($_GET)) {
     57        return false;
     58    }
     59   
     60    return true;
    4661}
    4762
     
    285300    # MUST end with a trailing slash. This is the *real* filesystem path where
    286301    # your plugin writes cache files using the <host>/<uri>/index.html layout.
    287     alias " . $cache_abs_path . "/;
     302    alias " . rtrim($cache_abs_path, "/") . "/;
    288303
    289304    # Optional debug headers (remove in production if you don't want to expose paths)
     
    291306    #add_header simple-page-cache-file \$request_filename always;
    292307
    293     # We expect the internal rewrite to point to an existing file under alias.
    294     # If it doesn't exist for some reason, fail closed with 404.
     308    # Only serve existing files under alias. Anything else -> 404.
    295309    try_files \$uri =404;
    296310}
     
    300314#   - \"/\" (home), \"/about\", \"/blog/\", \"/foo/bar\" (extensionless URLs)
    301315#   - Does NOT match assets like \".css\", \".js\", \".png\", \".xml\", etc. (they contain a dot)
     316#   - Does NOT match urls containingwp-admin
    302317#
    303318# Behavior:
     
    305320#   2) Bypass cache if query string is present or user is logged in.
    306321#   3) If the file exists -> internal rewrite to /__simple-page-cache__/... to serve it.
    307 #   4) Otherwise: do nothing here; request will continue and be handled by your
    308 #      existing locations (e.g., your current `location /` → WordPress fallback).
    309 location ~ ^/[^.]*$ {
     322#   4) On MISS/BYPASS -> hand off directly to WordPress front controller.
     323location ~* ^/(?!.*wp-admin)[^.]*$ {
    310324    # Absolute cache root and default file name
    311     set \$simple_page_cache_root " . $cache_abs_path . "/;
    312     set \$simple_page_cache_index index.html;
    313 
    314     # Build:
    315     #   - \$simple_page_cache_abs : absolute filesystem path to the cache candidate
    316     #   - \$simple_page_cache_rel : internal URI that maps to the same file via /__simple-page-cache__/ + alias
    317     #
    318     # Layout on disk (produced by your drop-in):
    319     #   <cache_root>/<host><uri>/index.html
    320     set \$simple_page_cache_abs  \$simple_page_cache_root\$host\$uri/\$simple_page_cache_index;
    321     set \$simple_page_cache_rel  /__simple-page-cache__/\$host\$uri/\$simple_page_cache_index;
     325
     326    # Absolute on-disk candidate and the internal URI to serve it
     327    set \$simple_page_cache_abs " . rtrim($cache_abs_path, "/") . "/\$host\$uri/index.html;
     328    set \$simple_page_cache_rel /__simple-page-cache__/\$host\$uri/index.html;
    322329
    323330    # Bypass cache if:
    324331    #  - the request has a query string (we don't cache query variants), OR
    325332    #  - the user is logged in (WordPress logged-in cookie).
    326     # We do this by clearing \$simple_page_cache_abs so the -f check fails and we won't rewrite.
    327     if (\$args != \"\") { set \$simple_page_cache_abs \"\"; }
    328     if (\$http_cookie ~* \"wordpress_logged_in_\") { set \$simple_page_cache_abs \"\"; }
     333    # Clear BOTH vars so we never jump to the internal serve location on MISS.
     334    if (\$args != \"\")                            { set \$simple_page_cache_abs \"\"; set \$simple_page_cache_rel \"\"; }
     335    if (\$http_cookie ~* \"wordpress_logged_in_\") { set \$simple_page_cache_abs \"\"; set \$simple_page_cache_rel \"\"; }
    329336
    330337    # Cache HIT:
     
    335342    }
    336343
    337     # Cache MISS or bypass:
    338 
    339     try_files \$uri \$uri/ /index.php?\$args;
     344    # MISS/BYPASS -> explicitly hand off to WordPress front controller
     345    # No FastCGI params here; your existing PHP handler will catch /index.php
     346    rewrite ^ /index.php\$is_args\$args last;
    340347}
    341348
     
    343350# 1. Add the above configuration to your nginx server block for " . $host . "
    344351# 2. Reload nginx: sudo nginx -t && sudo systemctl reload nginx
    345 # 3. Test by visiting your site - cached pages should be served directly by nginx
    346 # 4. Check nginx access logs to see cache hits (look for 'simple-page-cache-webserver: Hit' header)
    347 # 5. Remove debug headers in production by commenting out the add_header lines above
     352# 3. Test by visiting your site cached pages should be served directly by nginx
     353# 4. Check in your browser (private/incognito mode) to see if the cache is working (look for 'simple-page-cache-webserver: Hit' header)
     354# 5. Uncomment additional add_header lines to debug further or enjoy your faster site!
    348355";
     356
    349357
    350358    return $nginx_config;
     
    365373        . "    }\n"
    366374        . "}\n"
    367         . "if (!isset(\$_SERVER['REQUEST_METHOD']) || \$_SERVER['REQUEST_METHOD'] !== 'GET') return;\n\n"
     375        . "if (!isset(\$_SERVER['REQUEST_METHOD']) || \$_SERVER['REQUEST_METHOD'] !== 'GET') return;\n"
     376        . "if (!empty(\$_GET)) return;\n\n"
    368377        . "\$settings_file = '" . $settings_dir . $settings_filename . "';\n"
    369378        . "\$settings = [];\n"
     
    500509        'cache_dir' => $cache_dir,
    501510        'exclude_uris' => [],
    502         'plugin_version' => '1.1.0'
     511        'plugin_version' => '1.1.1'
    503512    ];
    504513    file_put_contents($settings_file, json_encode($settings, JSON_PRETTY_PRINT));
     
    552561            $settings = json_decode($settings_content, true);
    553562            if (is_array($settings)) {
    554                 $current_version = '1.1.0'; // Current plugin version
     563                $current_version = '1.1.1'; // Current plugin version
    555564                $saved_version = $settings['plugin_version'] ?? '0.0';
    556565
Note: See TracChangeset for help on using the changeset viewer.