[Solved] Membership based caching

#1
Hello,
I'm looking for a solution to our membership site running on WordPress.

The situation is this:

We have 3 levels of membership.
1. Not logged user
2. Logged but has no premium level
3. Logged and has premium level

For those who've got a premium level article is displayed in full length, the rest can see just the beginning.

Is it possible to serve premium cached content for premium users and for the rest the restricted content?

Example:

User1 is premium
User2 is premium
User3 is basic and is logged in.
User4 is not logged in, therefore is the basic level.

When User1 logs in and access a premium article /premium-article/ , generates cache of the article.
When User2 logs in and access /premium-article/ after User1, cached version of User1 is served.
When User 3 logs in and access /premium-article/, generate cache with restricted version.
When User4 access after User3 to /premium-article/, cached version is served that User3 has generated.
When User4 access first /premium-article/, generate the restricted version that after User3 will see after logs in and access /premium-article/

Is this possible? Thank you for your suggestions!
 
Last edited:
#3
Hi, sorry, it's Wordpress, I've edited my post.
I got a plugin and know it very well. Caching works fine only when a user is not logged in. I need caching for logged users and not serving private cache. Thank you
 

Pong

Administrator
Staff member
#4
What WordPress plugin do you use for membership level? the issue could be a tricky one, may not be that easy. How popular of the membership plugin? We might need to evaluate for a potentional feature request.
 
#5
Hello,
so there is WooCommerce membership plugin. I came with 2 solutions.

1. I wrote a plugin that fetches HTML via hook after LS makes optimization and store it as a file. Then I used a hook when I can check if user is premium, I check if the cached file exists and if yes, then is served and die(). So really another cache. This has an issue that still plugins need to be executed but it brought improvement, from 2 sec to 300ms on my local WP. There is an option to look in DB if a user if is a premium member but as I abandoned this way I wasn't looking for data in DB.

2. First I forced to cache URL /20 as all posts we wanted to cache starts with the year. Then for premium members, I set a cookie and make a redirect in .htaccess to /my-url?premium. That is a different version of /my-url/ so it's cached separately. Of course, when non-premium user tries to access /my-url?premium then is redirected to /my-premium/

For implementing into LS cache plugin for WP I see the major difficulty, how you going to distinguish between membership levels. Different plugins have different way to determine it. But maybe it's doable via hook. I think it would be very beneficial for membership sites with a similar situation to have the option to cache page based on the membership level.

I hope that helped!
 
Top