tractorcow / silverstripe-dynamiccache

Simple on the fly caching of dynamic content for Silverstripe
39 stars 27 forks source link

Multiple theme fail #5

Closed selay closed 11 years ago

selay commented 11 years ago

It fails for multiple themes, serving a wrong theme. Silverstripe supports multiple themes, like for example one for mobile and one normal site which is returned respectively depending on whether request comes from mobile or computer. But when this module is there, it breaks, serving the mobile theme to computer one, if the previous request cached was mobile. And it fails, throwing error that couldn't find a cache file etc.

tractorcow commented 11 years ago

I think you're right, @ielmin . The module cannot serve up user-customised content, even if that content is customised by comparing the User-Agent (which is how I understand that the silverstripe mobile module works).

If you want to get this working on mobile there are a couple of things you'll need to do:

Besides the SEO issues involved in conditionally serving up different content for the same url, this module simply won't handle multiple content on a single url. If you are using a multi-domain model then I think we could get it working however.

Any thoughts on my suggestion? Can you give me any more details of your use case so that I can better understand the requirements?

selay commented 11 years ago

I am using silverstripe's mobile module. Currently, the module allows using the same domain without adding m for mobile. When used, this module allows you in the Settings to assign a theme which will be used for mobile requests. The mobile module uses user agent detection to trigger the theme set for mobile sites in the cms. So, if you go to this site http://gpacstg.pvonline.com.au via a normal browser, it will serve a different theme and if you go via mobile device or you can use chrome plugin to pretend to be a mobile user and it will serve a different theme. I dont want to use a different domain or subdomain for the mobile. I want dynamic cache to remember which theme it cached. If it knows the theme name cached, it will serve correctly. I guess the cache folder should be named as part of the theme name. IN MY CASE: What I want to do is, your module can keep two cache versions, one for mobile and one for normal site. Because mobile theme provides a function isMobile(), you can actually call it when a http request comes to check if this one is mobile or not, and serve from the mobile cache folder not from the desktop site folder. At the same time, for caching, we can use that function to cache (of course, the set hour internal will apply). You can also use theme name to create cache folder so that different themes can have their own caches.

tractorcow commented 11 years ago

I'll develop something that I think will help solve your problem. it will be a good use case for "how to customise caching" for the docs. On Jul 10, 2013 5:26 PM, "ielmin" notifications@github.com wrote:

I am using silverstripe's mobile module. Currently, the module allows using the same domain without adding m for mobile. When used, this module allows you in the Settings to assign a theme which will be used for mobile requests. The mobile module user user agent detection to trigger the theme set for mobile sites in the cms. So, if you go to this site http://gpacstg.pvonline.com.au via a normal browser, it will serve a different theme and if you go via mobile device or you can use chrome plugin to pretend to be a mobile user and it will serve a different theme. I dont want to use a different domain or subdomain for the mobile. I want dynamic cache to remember which theme it cached. If it knows the theme name cached, it will serve correctly. I guess the cache folder should be named as part of the theme name. IN MY CASE: What I want to do is, your module can keep two cache versions, one for mobile and one for normal site. Because mobile theme provides a function isMobile(), you can actually call it when a http request comes to check if this one is mobile or not, and serve from the mobile cache folder not from the desktop site folder. At the same time, for caching, we can use that function to cache (of course, the set hour internal will apply). You can also use theme name to create cache folder so that different themes can have their own caches.

  • If cache duration set to 1 hour: and no cache exists or it has expired, when request comes, it checks what type (mobile or not) of request it is, and caches that one, say into mobile_cache or desktop_cache. \ If cache duration set to 1 hour: and cache time is still valid, when request comes, it checks its type and serves whichever is needed. I am looking into the module to see how I can modify it, but if you have any better flow idea, please let me know. Or maybe if you think there is a better way to do it, please let me know how I can quickly fix it. .

— Reply to this email directly or view it on GitHubhttps://github.com/tractorcow/silverstripe-dynamiccache/issues/5#issuecomment-20722319 .

selay commented 11 years ago

Great, thanks for that. I think the theme name is part of cached file names as part of the generated hash name, or is part of the folder name, then we can pick correct files for the theme currently in use. Can get current theme path in silverstripe, which means can know what theme will be used to get the correct cached version. Let me know if I can help with anything.

tractorcow commented 11 years ago

I think I can simply extend the getcachekey function to allow user code to add whatever extra filters they need. In your case you would set mobile yes/no to be the extra filter. You couldn't do it directly on theme because this all happens pre-db and route handling. On Jul 10, 2013 6:11 PM, "ielmin" notifications@github.com wrote:

Great, thanks for that. I think we theme name is part of cached file names as part of the generated hash name, or is part of the folder name, then we can pick correct files for the theme currently in use. Can get current theme path in silverstripe, which means can know what theme will be used to get the correct cached version. Let me know if I can help with anything.

— Reply to this email directly or view it on GitHubhttps://github.com/tractorcow/silverstripe-dynamiccache/issues/5#issuecomment-20723440 .

selay commented 11 years ago

yeah, it sounds fine.

selay commented 11 years ago

As i needed urgently, I fixed it in this way for now. It is working, thank you very and I really appreciate your quick response. getfunction

tractorcow commented 11 years ago

Yep, that seems to be the right place to put it. I'll formalise it and provide instructions.

tractorcow commented 11 years ago

Heya @ielmin , I've updated the code to better support your needs there. Hope it makes sense!

Documented at https://github.com/tractorcow/silverstripe-dynamiccache#customising-cache-behaviour