Question

Wordpress/Nginx partial page caching for logged in users?

I have a WordPress site (2 load balanced with a separate shared db server actually), and I have a growing number of users that login to get access to certain content areas of the site. Since the content (although not the access) is static, I would like to cache these pages for logged in users but I have the following problem:

Each of these pages contain links to internal resources that are controlled depending on the membership rights the user has. So for example, on a page of links some of the links will go to the content (if one has rights) and some will go to a “please subscribe for access” page.

I am researching the best way to cache these pages, here are some ideas:

  1. Set cookies based on rights, and cache the output of each page result that matches every combo of cookies

  2. Set cookie for rights and read that value in javascript and update the links (but this seems too hackable on the client)

Any other suggestions? Is there some better system out there for caching only parts of a page or fragment? Or something that caches every possibility but only serves the appropriate cached version based on user rights?

Thanks in advance for any suggestions or pointers!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I answered my own question (or at least have one answer). Here is what I am doing in case it helps anyone else:

  1. On login, I set a session cookie whose value is a combination of memberships the user has.
  2. I changed my fastcgi_cache_key to “$scheme$request_method$host$request_uri$cookie_memberships”;

Now, those pages are cached, and will show to the appropriate user based on their membership combination. So I get the benefit of fast cached pages while still respecting user rights.

Can you share the function that sets the cookie upon login?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.