Extension, Module

Archived
Forum
(read-only)

CE Cache

ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Causing Effect

1 of 2
1
   

CE Cache writing to, but not reading from Cache

Support (Resolved)

eboost
eboost

Hi!

I’ve been trying to get CE Cache to work for a while now. I’ve re-done the installation guide a couple of times, but to no avail. I’m at this point:

The static driver is showing up in the CE Cache Home. It is also writing files to the cache. However, when I’m browsing the website, it is still slow, and no debug information is being shown at the bottom. It seems like the driver is not being loaded?

I’ve tried replacing the %DOCUMENT_ROOT with my server path. Didn’t help.

My .htaccess containing the driver part looks (quite straightforward) like this:

#------------------- CE Cache Static Driver -------------------
RewriteCond %{REQUEST_URI} !^/rabo-bp-system [NC]
RewriteCond 
%{QUERY_STRING} !ACT|URL [NC]
RewriteCond 
%{REQUEST_METHOD} !=POST [NC]
RewriteCond 
%{DOCUMENT_ROOT}/static/ce_cache/f3fa8a/static%{REQUEST_URI}/index\.html -f
RewriteRule 
(.*) /_static_cache_handler.php%{REQUEST_URI}/index\.html [L,QSA] 

I am using Transcribe for multi-lingual. Is that interfering maybe?

Cheers,
Rutger

 

eboost
# 1
eboost

I was correct in assuming that Transcribe was getting in the way. I had to adapt the ce cache tag to:

{exp:ce_cache:stat:ic url_override="{transcribe:language_abbreviation}/{current_path}"
eboost
# 2
eboost

After this fixed my caching issue. I noticed that the cached entries broke my CSS link of the form:
http://www.domain.com/en?stylesheet - Since this served up the cached en/index.html file. I had to change:

<link rel=“stylesheet” href=”{stylesheet=embeds/stylesheet}”>

into

<link rel=“stylesheet” href=”{path=embeds/stylesheet}”>

Causing Effect - Aaron Waldon
# 3
Developer
Causing Effect - Aaron Waldon

Hi eboost!

I’m happy to see that you found the url_override solution and got everything sorted out.

I would highly recommend moving the style sheets from EE to flat files. EE literally loads dozens and dozens of files, and runs several database queries every time it runs. It’s a lot of overhead for simply serving up a style sheet.

Does that make sense?

ejaeDesign
# 4
ejaeDesign

Our static driver works fine on the homepage w/ Transcribe but on interior pages/templates this static tag:

{exp:channel:entries limit=“1” disable=“categories|custom_fields|member_data|pagination”}
{exp:ce_cache:stat:ic tags=“basic-content-{transcribe:language_abbreviation}|{entry_id}” url_override=”{transcribe:language_abbreviation}/{current_path}”}
{/exp:channel:entries}

Writes to the static folder but the URL does not read from it, thus taking the full load time when the URL is visited. When I take out the url_override parameter, the URL reads from the cache but the correct language does not pull up.

What can be the issue on the url_override parameter?

Also, can I use the {entry_id} as a cache breaking tag without wrapping the {exp:ce_cache:stat:ic} in an {exp:channel:entries} tag?

Thanks!

Causing Effect - Aaron Waldon
# 5
Developer
Causing Effect - Aaron Waldon

Hi ejaeDesign!

What can be the issue on the url_override parameter?

That static driver reads requests based on the Apache (or nginx) rewrite rules. If the URL matches up with the file path, it should work.

For example, if I cache an item using the static driver to “/test/ce_cache_static”, then Apache would look for “%{DOCUMENT_ROOT}/static/xxxxx/static/test/ce_cache_static/index.html”. If it finds that file, then it sends it to the _static_cache_handler.php file and displays the page.

Can you troubleshoot and see if your static item’s cache path and page URL match up?

Also, can I use the {entry_id} as a cache breaking tag without wrapping the {exp:ce_cache:stat:ic} in an {exp:channel:entries} tag?

I think you should be able to use the Add Tags tag anywhere in the page if using the static tag. Theoretically, this should work:

{exp:channel:entries limit="1"}
     {exp
:ce_cache:add_tag}{entry_id}{/exp:ce_cache:add_tag}
{
/exp:channel:entries}

{exp
:ce_cache:static} 
ejaeDesign
# 6
ejaeDesign

Hi Aaron,

Thanks for the quick reply! So this is what’s happening:

I double-checked the path to the static folder and that’s correct. I can confirm it by removing the url_override tag, which makes the page read from the cached file w/o a problem.

By adding the url_parameter tag, CE Cache creates an additional segment that corresponds to the hidden language variable used in Transcribe, as shown the screenshot.

So, Apache/htaccess/CEC cannot match the URL (/about) to the cached path (/en/about or /ko/about, etc.)

Is there a way to account for this extra language segment (“en”, “ko”, etc.)?

Thanks!

ejaeDesign
# 7
ejaeDesign

Also, thanks for the tip on the {add_tag} tag.

Can that {exp:channel:entries} be below the {exp:ce_cache:static} tag? If so, I can run it elsewhere in the template that already runs a {exp:channel:entries} loop.

Causing Effect - Aaron Waldon
# 8
Developer
Causing Effect - Aaron Waldon

Is there a way to account for this extra language segment (“en”, “ko”, etc.)?

If the URLs match the cache structure, it technically should work.

If you were to create a link to a transcribe page, what does the actual URL in the href look like?

Does it look like this?

/en/about 

Or does it have query strings, like this?

/about?language=en 

If the request to the server is “/en/about” then the corresponding cache item should be found if the URL matches it. If the URL is different, then I would need to know what it looks like to try to determine an .htaccess rewrite to match.

Can that {exp:channel:entries} be below the {exp:ce_cache:static} tag?

I believe the static tag can be added anywhere on the page and the tags should work.

ejaeDesign
# 9
ejaeDesign

Hi Aaron,

The URL looks like /about and not /en/about nor /ko/about on the front-end. For example, the following segment works for both EN and KO languages:

https://new.theologyofwork.org/about 

In other words, Transcribe does not show the first language segment (I believe it is ignored, like the Freebie segments).

So for the static cache, the front-end URL must match the cached directory like:

https://new.theologyofwork.org/en/about 
https://new.theologyofwork.org/ko/about 

or

https://new.theologyofwork.org/about 
https://new.theologyofwork.org/ko-about (different URL altogether) 

Thanks!

 

 

nacnewmedia
# 10
nacnewmedia

if you are using a separate index.php file for each language(a physical directory for each lang) then you’ll have be better off separating things using something like {exp:ce_cache:it id=“pagename__lang:{country_code}”}

Causing Effect - Aaron Waldon
# 11
Developer
Causing Effect - Aaron Waldon

Yeah, I agree that fragment caching is probably the way to go on this. Since some of the URLs don’t have any indication of which language they are for, there is no way for the .htaccess redirect to determine whether or not they have a cache file. The Transcribe docs say that the following works well:

{exp:ce_cache:it id="{transcribe:language_abbreviation}"


I suppose you could specify an .htaccess rewrite rule for each language, and then the default. This is probably kind of okay for a language or two, but in general, I would advise against this:

#------------------- KO Static Check -------------------
RewriteCond %{REQUEST_METHOD} GET
RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
RewriteCond 
%{DOCUMENT_ROOT}/static/ko/xxxxx/static/$1/index\.html -f
RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]

#------------------- EN Static Check -------------------
RewriteCond %{REQUEST_METHOD} GET
RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
RewriteCond 
%{DOCUMENT_ROOT}/static/en/xxxxx/static/$1/index\.html -f
RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]

#------------------- CE Cache Static Driver -------------------
RewriteCond %{REQUEST_METHOD} GET
RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
RewriteCond 
%{DOCUMENT_ROOT}/static/xxxxx/static/$1/index\.html -f
RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA] 

The reason that is not a great idea, is that .htaccess could potentially check the server for 3 files every time a page is requested.

Note: You would replace the xxxxx text snippets in the code above with the actual hash from your static driver installation page.

ejaeDesign
# 12
ejaeDesign

Thank you very much for the guidance, both of you.

So, I went ahead and made sure Transcribe is saving the static content on /en and /ko directories and added the following to the htaccess file:

<IfModule mod_rewrite.c>
 
#------------------- remove trailing slash -------------------
 
RewriteCond %{REQUEST_URI} !^/system [NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteRule 
^(.+)/$ /$1 [R=301,L,QSA]
 
#------------------- index.php -------------------
 #strip index.php from the URL if that is all that is given
 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
 
RewriteRule ^(([^/]+/)*)index\.phphttp://%{HTTP_HOST}/ [R=301,NS,L,QSA]
 #strip index.php/* from the URL
 
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php[NC]
 RewriteRule 
^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]
 #------------------- CE Cache Static Driver -------------------
 
RewriteCond %{REQUEST_URI} !^/system [NC]
 RewriteCond 
%{QUERY_STRING} !ACT|URL [NC]
 RewriteCond 
%{REQUEST_METHOD} !=POST [NC]
 RewriteCond 
%{DOCUMENT_ROOT}/static/ce_cache/710050/static%{REQUEST_URI}/index\.html -f
 RewriteRule 
(.*) /_static_cache_handler.php%{REQUEST_URI}/index\.html [L,QSA]
 
#------------------- EE -------------------
 #rewrite all non-image/js/css urls back to index.php if they are not files or directories
 
RewriteCond $!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteCond 
%{REQUEST_FILENAME} !-d
 RewriteRule 
^(.*)$ /index.php/$1 [L,QSA]
 
#------------------- KO Static Check -------------------
 
RewriteCond %{REQUEST_METHOD} GET
 RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
 RewriteCond 
%{DOCUMENT_ROOT}/static/ko/710050/static/$1/index\.html -f
 RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
 
#------------------- EN Static Check -------------------
 
RewriteCond %{REQUEST_METHOD} GET
 RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
 RewriteCond 
%{DOCUMENT_ROOT}/static/en/710050/static/$1/index\.html -f
 RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
 
#------------------- CE Cache Static Driver -------------------
 
RewriteCond %{REQUEST_METHOD} GET
 RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
 RewriteCond 
%{DOCUMENT_ROOT}/static/710050/static/$1/index\.html -f
 RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
</IfModule

The page is still not reading the cache however:

https://new.theologyofwork.org/about

What could I be missing?

ejaeDesign
# 13
ejaeDesign

Hi Aaron,
We’re planning to go live early next week—would you mind taking a look at the htaccess I posted above?
Thanks!

Causing Effect - Aaron Waldon
# 14
Developer
Causing Effect - Aaron Waldon

For the record, I really don’t recommend this approach. But, since you asked, your .htaccess should look like this:

<IfModule mod_rewrite.c>
 
#------------------- remove trailing slash -------------------
 
RewriteCond %{REQUEST_URI} !^/system [NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteRule 
^(.+)/$ /$1 [R=301,L,QSA]
 
 
#------------------- index.php -------------------
 #strip index.php from the URL if that is all that is given
 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
 
RewriteRule ^(([^/]+/)*)index\.phphttp://%{HTTP_HOST}/ [R=301,NS,L,QSA]
 #strip index.php/* from the URL
 
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php[NC]
 RewriteRule 
^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]
 
 #------------------- KO Static Check -------------------
    
RewriteCond %{REQUEST_METHOD} GET
    RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
    RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
    RewriteCond 
%{DOCUMENT_ROOT}/static/ko/xxxxxx/static/$1/index\.html -f
    RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
    
    
#------------------- EN Static Check -------------------
    
RewriteCond %{REQUEST_METHOD} GET
    RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
    RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
    RewriteCond 
%{DOCUMENT_ROOT}/static/en/xxxxxx/static/$1/index\.html -f
    RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
    
    
#------------------- CE Cache Static Driver -------------------
    
RewriteCond %{REQUEST_METHOD} GET
    RewriteCond 
$!\.(css|js|gif|jpe?g|png[NC]
    RewriteCond 
%{QUERY_STRING} !ACT|URL|CSS|preview [NC]
    RewriteCond 
%{DOCUMENT_ROOT}/static/xxxxxx/static/$1/index\.html -f
    RewriteRule 
^(.*?)/?$ /_static_cache_handler.php/$1/index.html [NE,L,QSA]
 
 
#------------------- EE -------------------
 #rewrite all non-image/js/css urls back to index.php if they are not files or directories
 
RewriteCond $!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteCond 
%{REQUEST_FILENAME} !-d
 RewriteRule 
^(.*)$ /index.php/$1 [L,QSA]
</IfModule

You’ll need to ensure that the ‘xxxxxx’ matches the correct hash for your site. You can figure out what that should be by looking in your Static Driver Installation Instructions page in the CE Cache module, or by looking at the folder path on your filesystem (it would something like “/static/ce_cache/xxxxxx/static/”, where the xxxxxx is the hash you should be using).

The above .htaccess assumes that you are caching your pages using the static tag like you had previously posted:

{exp:ce_cache:stat:ic url_override="{transcribe:language_abbreviation}/{current_path}"

Also, be sure the update the hash in the _static_cache_handler.php file.

There are also setup and debugging instructions in the Static Driver Installation Instructions page in the CE Cache module page. Please check those too to see if any of those steps were missed or help to debug and correct a potential issue.

ejaeDesign
# 15
ejaeDesign

Hi Aaron,

Thanks for the detailed answer, once again. We still had issued with the methods posted above, so we simply made all KO entries have a unique URL.

However, now we have a different issue. We need the old URLs to redirect/rewrite to the new ones. For example, this URL:

https://new.theologyofwork.org/ko/old-testament/psalms-and-work/book-4-psalms-90106/human-creativity-with-god-psalm-104

Should go to:

https://new.theologyofwork.org/ko-old-testament/ko-psalms-and-work/ko-book-4-psalms-90106/ko-human-creativity-with-god-psalm-104

I was able to do this by adding the rewrites:

RewriteRule ^ko/([a-zA-Z0-9-]*)$ /ko-$1 [L,R=301]
RewriteRule 
^ko/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)$ /ko-$1/ko-$2 [L,R=301]
RewriteRule 
^ko/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)$ /ko-$1/ko-$2/ko-$3 [L,R=301]
RewriteRule 
^ko/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)$ /ko-$1/ko-$2/ko-$3/ko-$4 [L,R=301]
RewriteRule 
^ko/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)/([a-zA-Z0-9-]*)$ /ko-$1/ko-$2/ko-$3/ko-$4/ko-$5 [L,R=301] 

Above the default CE Cache rewrites (screenshot):

<IfModule mod_rewrite.c>
 
#------------------- remove trailing slash -------------------
 
RewriteCond %{REQUEST_URI} !^/system [NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteRule 
^(.+)/$ /$1 [R=301,L,QSA]
 
#------------------- index.php -------------------
 #strip index.php from the URL if that is all that is given
 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
 
RewriteRule ^(([^/]+/)*)index\.phphttp://%{HTTP_HOST}/ [R=301,NS,L,QSA]
 #strip index.php/* from the URL
 
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php[NC]
 RewriteRule 
^index\.php/(.+) http://%{HTTP_HOST}/$1 [R=301,L,QSA]
 #------------------- CE Cache Static Driver -------------------
 
RewriteCond %{REQUEST_URI} !^/system [NC]
 RewriteCond 
%{QUERY_STRING} !ACT|URL [NC]
 RewriteCond 
%{REQUEST_METHOD} !=POST [NC]
 RewriteCond 
%{DOCUMENT_ROOT}/static/ce_cache/710050/static%{REQUEST_URI}/index\.html -f
 RewriteRule 
(.*) /_static_cache_handler.php%{REQUEST_URI}/index\.html [L,QSA]
 
#------------------- EE -------------------
 #rewrite all non-image/js/css urls back to index.php if they are not files or directories
 
RewriteCond $!\.(css|js|gif|jpe?g|png[NC]
 RewriteCond 
%{REQUEST_FILENAME} !-f
 RewriteCond 
%{REQUEST_FILENAME} !-d
 RewriteRule 
^(.*)$ /index.php/$1 [L,QSA]
</IfModule

Now the redirect works but caching no longer does. How can I resolve this?

Thanks again!

1 of 2
1