Fastcgi_cache, Mobile theme, Purge


#1

Hello there,

I am using Jetpack mobile theme, so I want different cache for each version, desktop and mobile. Not a problem, just need to first identify if user-agent is mobile, set a variable (mobile=1) and attach this variable to the cache_key.

fastcgi_cache_key $scheme$request_method$host$request_uri$mobile_request";

We then use the server block to identify mobile visitors.

set $mobile_request 0;  
if ($http_user_agent ~* "(android|iphone)") {  
set $mobile_request 1;  
}  

Thats not all user agents! This is just a sample

Everything works fine I have two cache versions one for mobile theme and another for desktop, all on same domain. Problem is with cache purge. If I append the $mobile_request variable to the purge cache key identifier, only the version of my useragent (desktop) gets purged. If I leave it empty I get a 404 - cache not fond / not cached on log.

How can I purge both versions?

Best regards!


Seperate Mobile v Desktop Cache in Redis
Nginx fastcgi_cache and Wordpress wp_is_mobile function - not showing correct page versions to correct user devices
Fascgi AND W3 mobile and desktop caches - desktop cache corrupted with mobile elements
#2

@dominique-dutra

This is known limitation of nginx's purge module - https://github.com/FRiCKLE/ngx_cache_purge

One idea was to use wildcards but it has limitation from nginx-core - https://github.com/FRiCKLE/ngx_cache_purge/issues/5

Fixing this issue is on our list as well.

We will try to see what we can do using http://wordpress.org/plugins/nginx-helper/


#3

Rahul.
Thanks alot.
I am using nginx-helper plugin and it works great, except for the wildcard purge.

I can one see a hardcoded solution and that I cannot use. So I guess I’ll have to wait on nginx side (wildcards) for that one.

Best regards.


#4

From Nginx side, we shouldn’t wait for any wildcard things. Its something very complex and not inline with md5-hashing.

First workaround we are planning is: in nginx-helper give a textarea where you can specify additional header per line (in your case you will give 2 lines for 2 user-agents sample - one for desktop and one for mobile).

Then nginx-helper will initiate a normal purge request for every-line in textarea. For this to be efficient, we need to add some kind of job-queue (e.g. redis)

Second approach is: explore possibilities with memcahce. If memcache keys can support wildcards, regex, etc, the use memcache-based store rather than fastcgi-cache.

Both will need a lot of work and testing. That is why it will take time!

In meantime, we use “Purge Cache” option integrated in wordpress admin-bar to quickly flush entire fastcgi-cache.


#5

Thanks Dominique, I used the block slightly different at this stage just to skip caching for mobile users.

Where should the fastcgi_cache_key $scheme$request_method$host$request_uri$mobile_request”; be set? just in the server block as well?

I’m keen to keep modifications to a minimum to reduce chance of issues with easyengine updates etc.

Cheers
James


#6

Hmm just realised I’ve been doing double caching, I had been caching with W3 Total Cache page cache as well as fastcgi. For some reason I thought the files generated by W3TC were used by fastcgi. Anyway, have disabled page cache on W3TC and think I can see where the cache key needs to be set.


#7

Hi Rahul, this topic is several years old. Has nginx-helper been updated to clear all caches including mobile versus other like in the original post?

Thanks!


#8

No. But we are close with new redis full-page cache option (--wpredis). Redis has wildcard support. We are planning to provide a wordpress hooks/settings which people can use to provide additional purge URL patterns.


#9

Awesome, does Redis support multiple caches like described in the very first post of this thread?

Thanks!


#10

Yep. Redis and Fastcgi-cache supports similar caching rules.

Only difference is - redis cache doesn’t hash keys so we can use wildcard directly. Fastcgi-cache uses hashing so wildcard purge cannot be done directly or efficiently or both!

Nginx-plus (paid) version has support for wildcard Fastcgi-cache purge in case you like to have a look at it - http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_purge


#11

Thanks Rahul, you might remember I have been struggling with this issue for some time (Nginx fastcgi_cache and Wordpress wp_is_mobile function - not showing correct page versions to correct user devices) so stumbling upon this thread and finding the answer was quite easy to implement was great. I will do some searching myself, but do you know of any good guides for implementing the multiple caches using redis/WPredis through Easy Engine? Thanks!


#12

hi is there any update on this issue? or not how can i purge manually mobile cache? ee clean --all doesn’t help.


#13

see How to - Fastcgi_cache & Desktop with Mobile versions - Purging with GET Requests


#14

Does anyone know if the caching issues in this thread (mobile versus non-mobile) are also present when using redis instead of fastcgi?


#15

Hello,

I need a solution to separate the cache from the desktop with the mobile cache. Can someone help me?


#16

see first post in this thread


#17