Table of Contents

LSCache for WP Page Content Not Updating Correctly

If your site uses a plugin that updates the content of a page without editing/saving that page, such as a “like” button that updates a counter when pressed using ajax, LSCache will not be made aware that the page should be purged from cache. As long as the now outdated copy of the page is still in cache and being served, it will appear like these changes never happened.

Solution

Add our LiteSpeed_Cache_API::purge_post($id) API call to the offending plugin to have it notify LSCache that the page should be purged.

Testing

  1. Purge the cache and with the inspector open (right click page → Inspect) access the page as a guest/non-logged in user.
  2. In the inspector, click into the Network tab and select the page request - this is usually the first entry. With this selected, click the Header tab and check that the Response Header does not contain “X-LiteSpeed-Cache: hit”.
  3. (If your plugin updates on each visit, skip this step) Refresh the page. You should now see “X-LiteSpeed-Cache: hit” in your response header. This indicates that the page was served from cache.
  4. Trigger your plugin and make sure that the page is updated as expected.
  5. Refresh the page one last time. “X-LiteSpeed-Cache: hit” should once again be gone from the Response Header and the page should still contain the updated information.