Hi!
I'd like to add ability for dynamic cache folder.
History:
I'm doing phanganist.com - drupal 7 based website, hosted on nginx+php-fpm.
I found, that my mobile and desktop users get completely same cache and that's make some problems.
For example, I use panels module and different panel variants, depending on mobile/tablet/desktop users (I use php mobiledetect lib). But, sure, they all use same url, so if mobile user get page 1st - desktop users will get "mobile version cached" page.
Thinking about way, how to manage it more or less nicely, I've got an idea to remove php mobile detection and move it to nginx, to get more flexibility of controll cached pages. So, I've got idea to separate cache folders.
Thinking about implementation I thought that it will be nice to have cache folder structure something like this:
- cache
--desktop
--mobile
--tablets
--robots
instead of simple
-cache
--normal
for everybody.
this will give more control on nginx level, and faster working.
example of nginx conf
#some mobile detect code
#with result variables $is_desktop/$is_mobile/$is_tablet/$is_robot
#and $device_type = 'mobile'/'desktop'/'tablet';
location / {
try_files $uri @cache;
}
old nginx cache location
location @cache {
#some confs
try_files /cache/normal/$host${uri}_${args}.html @drupal;
}new cache location
location @cache {
#some confs
try_files /cache/${device_type}/$host${uri}_${args}.html @drupal;
}also, other separations can be done on nginx side, but all of this ideas requires boost support.
but hardcode it to boost boost_get_normal_cache_dir() looks stupid for me, so, I got idea to create alter hook for getting boost normal cache dir, so after it's possible create separated modules, for implementation of "special normal cache dir".
I attach my patch, and hope I did "feature request issue" correct =) (I'm sorry if not - it's my 1st experience of communications on drupal.org)
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | mobile-detect.conf_.txt | 5.58 KB | abrakadobr |
| boost.patch | 1018 bytes | abrakadobr |
Comments
Comment #2
abrakadobr commentedso, finally this is full idea solution:
1. apply boost patch
2. add mobile-detect.conf (file attached) to your http/https nginx configuration. It will define new variable named $device_type, can be one of next values: desktop, mobile, tablet, bot.
3. modify your drupal website nginx configuration file to pass $device_type to php_fpm. I don't want use cookies, cuz I don't want give to user ability play with it. So this is my way:
Now we can get it inside php scripts with $_SERVER['DEVICE_TYPE']
3.1 nginx -t
3.2 nginx -s reload
4. create your module to separate cache folders
my module name is "boost_dynamicdir" and it is very simple, only one hook with one line of code
5. Success! Now in /cache/ folder I see separation of cached pages for mobiles, tables, desktops and even bots =)
so now i'm sure, that mobile users can't get desktop caches, etc.
6. More than this - now I don't need any php libraries to detect device, i just need to check $_SERVER['DEVICE_TYPE'], but this is thanks to nginx =)
Comment #3
nmalinoski commentedTo be clear, this would be for sites that output different content depending on the user agent, NOT alternate m. sites or sites with responsive design?
Comment #4
abrakadobr commentedThis is multi-use solutions (that's why i implement it as a hook) for any cache separations.
How do i see main idea of boost - after we build page using loooong php and mysql - we want to return this builded page without involving even php to this process, so everything should be done on webserver side (webserver check for cached page existing)
So, for sure, 1st idea i'm getting - detecting user agent. But, it can be used for whatever we want.
Let's say, separate caches by languages:
or, I want to separate caches for registered and anonymouses using some cookies
or i want to separate caches by geoip
.....
for sure, this is not "clear php" - your webserver should be configured to support your idea.. but anyhow I see this solution just as "do whatever u can imagine for separating caches on webserver" (nginx or apache or whatever).