Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Escape in static caching? Tags created when not cached?

Status Resolved
Add-on / Version Speedy 1.3.1
Severity
EE Version 5.4.2

Hop Studios

May 12, 2021

Hello there,

Is it possible to actually have the escape logic in static caching?

Also a separate question, I set up these ignore settings

$config['speedy_driver'] = 'static';
$config['speedy_static_enabled'] = 'yes';
$config['speedy_static_settings'] = [
    'ignore_urls' => [
        ['url' => '^[a-z]{2}/store'],
        ['url' => '^[a-z]{2}/search'],
        ['url' => '^[a-z]{2}/donate'],
        ['url' => '^[a-z]{2}/store/.*'],
        ['url' => '^[a-z]{2}/search/.*'],
        ['url' => '^[a-z]{2}/donate/.*'],
        ['url' => '^store'],
        ['url' => '^search'],
        ['url' => '^donate'],
        ['url' => '^store/.*'],
        ['url' => '^search/.*'],
        ['url' => '^donate/.*']
    ],
];

When I visit those pages they don’t get cached but a row will be inserted into exp_speedy_tags table. Here’s my template code:

{exp:speedy:static tags="{if layout:speedy_tags}{layout:speedy_tags}{/if}" url_prefix="{if publisher:current_language_id != publisher:default_language_id}{publisher:current_language_code}{/if}"}

Don’t know if this is intended for other reasons.

- Gil

#1

BoldMinded (Brian)

May 12, 2021

I’ll take a look at the tag thing, that is odd.

To answer your first question, no there isn’t a way to use the escape tag in static caching since it is designed to bypass EE entirely. What you’re referring to is “hole punching”. If you need to have part of a static page not cached, your best bet is to make an Ajax request to a partial that contains the non-cached data, like a user profile or shopping cart thing in the header of a page.

#2

Hop Studios

May 12, 2021

Let’s say if I want to use PHP to read cookie `exp_session` to determine if the user is logged in. Is there a file (maybe in utilities) that I can add this logic to? Maybe I’ll append a $_GET to show the non-cached version (which is possible right like ?nocache=1).

- Gil

#3

BoldMinded (Brian)

May 14, 2021

There isn’t anything like that, sorry. Sounds like custom work. You’d have to add something to the index php file that Speedy generates.

#4

Hop Studios

May 14, 2021

Can you point me in the right direction where the index PHP file is generated?

- Gil

#5

Hop Studios

May 18, 2021

Hello Brian,

In case you missed my previous message, can you please give me some hints on what files I might want to look at to modify the index.php generation process? Thanks!

- Gil

#6

BoldMinded (Brian)

May 18, 2021

There really is no great place to intercept b/c if you’re using static caching, each cached page is it’s own php file. They all load the static/utilities/StaticCacheHelper.php file though, but if you modify that Speedy might try to regenerate it if you change any cache settings. You might be better off changing your htaccess file to load a custom index.php file, that then loads the cache file, e.g. what is in your htaccess file: /static/default_site/static%{REQUEST_URI}/index\.php [L,QSA]

#7

Hop Studios

May 21, 2021

Hello Brian,

I’d like to share my approach to enable a login check. In StaticDriver.php around line 82 I added:

if (!empty(\$_COOKIE['exp_sessionid'])) {
    \$uri = parse_url(\$_SERVER['REQUEST_URI']);

    \$current_url = (isset(\$_SERVER['HTTPS']) && \$_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . \$_SERVER['HTTP_HOST'] . \$uri['path'] . '?no_cache=1' . (!empty(\$uri['query']) ? '&' . \$uri['query'] : '');

    header('Location: ' . \$current_url);
}

and in my .htaccess file I added no_cache to the condition

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/contentzsystem [NC]
    RewriteCond %{QUERY_STRING} !ACT|URL|no_cache [NC]
    RewriteCond %{REQUEST_METHOD} !=POST [NC]
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{DOCUMENT_ROOT}/static/default_site/static%{REQUEST_URI}/index\.php -f
    RewriteRule ^ /static/default_site/static%{REQUEST_URI}/index\.php [L,QSA]
</IfModule>

This obviously doesn’t check if the user’s logged in roles/groups but we don’t need that for this site.

- Gil

Login to reply