cachify icon indicating copy to clipboard operation
cachify copied to clipboard

Caching for specific user roles

Open Geschan opened this issue 8 years ago • 7 comments

It would be useful if the cache can be enabled/disabled for specific user groups. For example in a WooCommerce shop: cache enabled for customers (as cart, checkout and my-account aren't cached anyways), cache disabled for admins and all other roles (especially roles with activated admin-bar).

Geschan avatar Aug 16 '16 14:08 Geschan

You can use the option "No cache generation by logged in users" for that.

If you need more control there is already a hook for that: cachify_skip_cache

Here is an example: https://gist.github.com/Zodiac1978/5c95a4f70daa73171e4462bbe817759b

Zodiac1978 avatar Aug 16 '16 15:08 Zodiac1978

The option "No cache generation by logged in users" is for all users, so not what I suggested.

I'll have a look at cachify_skip_cache but it would be a nice feature to add in a future version at the configuration page.

Geschan avatar Aug 16 '16 15:08 Geschan

Thanks for your input @Geschan!

So basically you suggest turning the "No cache generation by logged in users" checkbox into an option where you could say e.g. "Only enable caching for users with role author or higher" . Does that sound about right?

swissspidy avatar Aug 16 '16 15:08 swissspidy

Basically yes. A WooCommerce customer is also a logged in user, but there is no need of excluding him from the cache. In most cases he will get the same content as the anonymous user does - except of the cart, checkout, my-account and some API requests which are already excluded by the DONOTCACHEPAGE constant or other rules.

Geschan avatar Aug 16 '16 16:08 Geschan

So basically you suggest turning the "No cache generation by logged in users" checkbox into an option where you could say e.g. "Only enable caching for users with role author or higher".

If we enable cache generation for user roles with an active admin bar this would be a problem.

Even if we check is_admin_bar_showing there could be Edit links inside the theme which shouldn't be cached.

Zodiac1978 avatar Aug 16 '16 21:08 Zodiac1978

Yeah enabling caching for logged-in users would mean not showing the toolbar or any Edit links to them as if they were normal visitors.

To improve performance for logged-in users, we should think about integrating #31. Simply put, an object cache is a a key-memory store which gets populated so WordPress doesn't have to call the database dozens of times.

swissspidy avatar Aug 17 '16 06:08 swissspidy

There might be a problem with caching of regular users, but I'm rather talking of WooCommerce customers and similar with no rights to change any content on the site at all (except of writing comments). It would be a good feature for an "expert configuration" for people who know what problems the caching of logged-in users might cause.

Geschan avatar Aug 23 '16 08:08 Geschan