unlcms / UNL-CMS

Drupal 7 implementation at the University of Nebraska–Lincoln
http://unlcms.unl.edu/
GNU General Public License v2.0
4 stars 13 forks source link

WIP (idea) - UNL_CAS smart cache #924

Closed mfairchild365 closed 7 years ago

mfairchild365 commented 7 years ago

This is more pseudo code than anything and would need to be heavily tested. The ideas is that right after authentication with CAS (and before LDAP lookup or account creation), check if the user even needs to be logged in. Then if the user does not need to be logged in, set a cookie for the site's domain+path that tells varnish to always cache (ignore the unl_sso cookie).

In other words:

If the user tries to log in (gateway auth via SSO) do the following:

  1. perform the gateway auth
  2. if user has role
    1. log them in as usual
  3. if user has no role (or is an 'authenticated user')
    1. do not log them in and set a cookie unlcms_force_varnish, when varnish can then use to force varnish caching even if the SSO cookie is set.

There is also some checking to see if the unl_access module is enabled or if the smart caching was disabled for the site in the configuration. This can 'smart checking' can be vastly improved, but it gets the point across.

I'm not sure if this is the best approach, or if I covered all the necessary cases. I also don't know how to configure varnish to check for the new cookie, but I'm guessing its possible.

How to configure varnish:

I haven't actually tried this yet, but I think it should work.

After all of the other checks to see if content should be not cached, we could add a check like this

if (req.http.Cookie ~ "(^|;\s*)(unlcms_force_varnish=true)(;|$)"){
    //force varnish (bypass the unl_sso cookie), another alternative might be to unset the unl_sso cookie here
    return(hash);
}

Questions

mfairchild365 commented 7 years ago

@ericras I pushed my brach to the upstream repo so that we can both work on it. https://github.com/unlcms/UNL-CMS/tree/smart-cache

I will close this PR.

ericras commented 7 years ago

Drupal 7 caching improvements