2

I'm creating a module which interacts with an external API that handles authentication and completely bypasses the Drupal authentication system. This means that users logged-in from the API side are seen as anonymous users. The module utilizes the PrivateTempStore class to store user sessions. This works as expected.

At the moment, any user session sensitive blocks or pages that my module outputs are set to have a maximum cache lifetime of zero to ensure that the user's account page is not cached.

Is this the correct approach, or should I disable the Internal Page Cache module, which specifically targets anonymous users?

The site will be hosted on the Acquia platform; Varnish will be likely used.

3
  • Using an external system for authentication is fine enough, but I don't quite understand why you don't store whatever you need to store in the session anyway? You can do that for "anonymous" users too, the session storage doesn't care about that. Contrib modules like Poll and Flag do that too. You should get a bunch of things for free then, like disabling page cache and varnish should then also work without special configuration (I assume acquia has it pre-configured to respect the default drupal session cookies, haven't used that myself yet, I'm a platform.sh user :)).
    – Berdir
    May 18, 2016 at 18:51
  • That said, you can implement your own Request/ResponsePolicy implementation. implementation to opt out of page cache in a more generic way. the basic auth module does that for example. Also not quite sure how you handle authentication, drupal kind of has a pluggable authentication system that you could hook into (not an actual hook ;)), so that there's still something like a "current user". Sounds like you might hit some limitations there, especially with other modules if they expect a full user entity there.
    – Berdir
    May 18, 2016 at 18:55
  • Page caching isn't for anonymous versus authenticated users. It's about having a session or not.Private temporary store requires a session as well. Unless you have a ton of data to store (that's what it is for, storing things like views being edited), just put it in the session. Then you also don't have to worry about your session not being kept.
    – Berdir
    May 19, 2016 at 18:51

1 Answer 1

0

Private TempStore always generate Anonymous Session. That means If you are using any Caching Layer for your Application it always break. either in Acquia or other platform.

May be you can use Browser LocalStorage for saving data and sync it when its required. it will help you to cache your pages.

In Acquia, cookie based cache variation Generation possible so you have to create cookie and based on that value you can generate cache tags.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.