keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

caching for logged in users #19

Closed centminmod closed 4 years ago

centminmod commented 6 years ago

WP Rocket has caching for logged in users as a feature. Was wondering if it's a planned feature in Cache Enabler's road map ?

theDanielJLewis commented 6 years ago

This is one of the reasons I currently use WP Rocket instead of Cache Enabler.

per4mance commented 6 years ago

That's the reason why I left WP Rocket because they cannot cache logged-in users if you use WordPress with BuddyPress. WP Rocket Cache is useless and a bad paid version. Follow what Lucy (WP Rocket) wrote on Februrary, 24th 2017 (after the team tried to fix it starting a year before).

**Lucy from WP Rocket here. Caspar is on holiday at the moment, so I'm afraid I have to answer you in English. 😳

I appreciate that working with BuddyPress is difficult. I'm not sure that the solution is only with us because the way that BuddyPress works makes some features incompatible with page caching in general (not just with our plugin). It's a known issue on their side.

We don't have any specific updates on this yet, but it is on our radar. Thanks for re-stating your interest this feature, keep your eye on our changelog and Roadmap for updates in the future.**

Never got any feedback anymore and I paid almost $100 for licenses.

centminmod commented 6 years ago

@per4mance ah interesting insight wasn't aware WP Rocket logged in user caching had issues !

per4mance commented 6 years ago

Up today didn't found any caching plugin that achieved to cache logged-in users

theDanielJLewis commented 6 years ago

Up today didn't found any caching plugin that achieved to cache logged-in users

I'm pretty sure WP Super Cache and W3 Total Cache both have it as an option.

svenba commented 6 years ago

We don't plan to implement this at the moment but feel free to create a pull request.

coreykn commented 4 years ago

I'd like to reopen this issue for discussion as I think this would be good to implement. Your input on this would be appreciated (@lukecav it'd be great to hear your feedback as well because you also requested this feature).

Currently if a cached page exists a logged in user can actually receive that cached page if the cookies exclusion is updated. However, if a page has not been cached yet a logged in user will not generate and receive the cached page even if the cookies exclusions is updated (because checking if a user is logged in is being done in the _bypass_cache() method).

I propose that checking if a user is logged in is removed and instead control this through cookies instead. By default the cookies exclusion set will not cache pages for logged in users, but this can be updated to allow logged in users to receive cached pages. If caching needs to be bypassed for certain user roles, such as admin, a custom cookie can easily be set for that user role and then excluded (e.g. user_admin=1).

erikdemarco commented 3 years ago

Any update about this feature?

coreykn commented 3 years ago

@erikdemarco, added in PR #95. Available since version 1.4.0.

erikdemarco commented 3 years ago

@coreykn I'm sorry I dont get it.

Yes in the pull request, is_user_logged_in() check is removed. But I dont get It what is the purpose?

See this line: https://github.com/coreykn/cache-enabler/blob/cb8942db350aa5cec0a8d0b0e8f04ee20b55631c/inc/cache_enabler.class.php#L1353

All logged in user have "wordpress_logged_in" cookie. So it will be bypassed. Its still same like if is_user_logged_in() not removed.

Maybe you didnt understand what @centminmod was saying. Caching for logged in user means every logged in user will have a unique cache for each page they request. So every page will have different version for every logged in user. Thats how WP-Rocket logged in cache works. https://docs.wp-rocket.me/article/313-user-cache

And please see this like: https://github.com/keycdn/cache-enabler/blob/a50b3f4fe2b9235ba5be3a3a983852f900b72966/inc/cache_enabler_disk.class.php#L627

The cache file only based on url path and other things. So every page still shared across users.

The cache file (cache key) should be based on the value of this cookie wp-postpass|wordpress_logged_in|comment_author So it will be unique for each user For example wp-rocket, use the value of wordpress_logged_in as the hash for the filename (not just url path): Like this: https://github.com/wp-media/wp-rocket/blob/aea8f96b0725f900deaa337af2f87c37277676ff/inc/front/process.php#L235

coreykn commented 3 years ago

Cache Enabler doesn't currently support creating a separate cached version for logged in users.

coreykn commented 3 years ago

Cookie-based caching is on our list of potential features that we want to introduce in the future. Please feel free to create a new issue for this feature request if you'd like to track its progress here.