• Resolved Mikko Saari

    (@msaari)


    When using LS Cache with ActivityPub, sometimes the JSON content from ActivityPub gets cached instead of the actual page. Both versions are served from the same URL, but the ActivityPub request comes with an Accept: application/activity+json header.

    Is there a way to prevent LS Cache from caching the JSON output, or to have a different cache for those requests?

Viewing 15 replies - 1 through 15 (of 22 total)
  • Plugin Support litetim

    (@litetim)

    Thread Starter Mikko Saari

    (@msaari)

    “Do not cache URIs” doesn’t help. The URI is the same. The only difference is the “Accept” header.

    “Cache REST API” doesn’t help either; these are not REST API calls. These are plain front end calls, just with a different “Accept” header.

    Ideally, LS Cache would respect the “Accept” header and would cache both the HTML and JSON content separately, or at least not serve HTML from the cache when the “Accept” header requests JSON.

    For example, you can see how WP Super Cache includes the “Accept” header in the cache tag if it’s not “text/html”: https://github.com/Automattic/wp-super-cache/blob/004a3c3a21363578f25976dfdbe6a8dd40ae0f96/wp-cache-phase2.php#L34 This way the cache won’t return the wrong content type.

    Plugin Support litetim

    (@litetim)

    @msaari
    Please send a report from LSC => Toolbox => Report => click on “Send to litespeed” then share the ID with me

    Thread Starter Mikko Saari

    (@msaari)

    BYUAVDFL. I’m using the ActivityPub plugin.

    For example, https://www.lautapeliopas.fi/artikkelit/kymmenen-vuotta-sitten-2015/ returns the HTML page and https://www.lautapeliopas.fi/?p=43695 with the “Accept: application/activity+json” header returns the ActivityPub JSON page (without the header, it returns the HTML page). This works, and right now when I test this, both pages show a “hit” from LS Cache.

    However, occasionally the ActivityPub JSON gets cached so that visitors to https://www.lautapeliopas.fi/artikkelit/kymmenen-vuotta-sitten-2015/ see only the ActivityPub JSON. This happens rarely, but this specific page was released a couple of days ago and I already got two reports from users who got the JSON instead of the HTML.

    Plugin Support qtwrk

    (@qtwrk)

    RewriteCond %{HTTP:Accept} application
    RewriteRule ^ - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+isjson]

    okay , what you are looking for is more like a cache vary

    please try add this at top of your .htaccess

    If lightspeed cache does support the vary header you can go to the ActivityPub advanced settings and enable that!

    Thread Starter Mikko Saari

    (@msaari)

    Nice! Those are some well-hidden advanced settings 😉 It would be nice to have some note that these advanced settings exist… If I enable that setting, are the .htaccess modifications necessary?

    @msaari it is on purpose that there is no documentation about it ☺️

    it is too easy to break things with these settings!

    Thread Starter Mikko Saari

    (@msaari)

    @pfefferle Maybe add a check for some of the most-used cache plugins and show a warning? “Hi, I see you’re using a cache plugin, check this setting to avoid problems with the cache”?

    @msaari if you can verify that the setting fixes your issue, I will change the default behaviour of the vary header setting when LiteSpeed Cache is active.

    Thread Starter Mikko Saari

    (@msaari)

    Unfortunately, this is something I can’t solidly verify – this is something that happens occasionally, and most of the time I don’t even hear of it. If I hear no complaints within a year, it’s probably fine…

    Plugin Support qtwrk

    (@qtwrk)

    hi @pfefferle , you may need to explicitily insert the rules I mentioned at top of htaccess, in order to tell cache engine to vary header , and it’s on the condition with accept header , not by the vary header though.

    <IfModule LiteSeed>
    RewriteCond %{HTTP:Accept} application
    RewriteRule ^ - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+isjson]
    </IfModule>

    better to enclose it with ifmodule , and also only insert it if LSCWP is enabled, you can check it by if (defined('LSCWP_V'))

    • This reply was modified 1 year ago by qtwrk.
    Thread Starter Mikko Saari

    (@msaari)

    @pfefferle I can now confirm that the Vary header setting alone does not solve the problem.

    Thanks for the feedback @msaari ! With the next version, we provide an option to disable Content-Negotiation for user facing sites. This might be another option, to prevent JSON in the cache.

    I will also work on an integration for the LiteSpeed Cache Plugin, like we currently did for Surge: https://github.com/Automattic/wordpress-activitypub/pull/1648

    Maybe we can automatically add the .htaccess rules if both plugins are installed. I will drop an update here, maybe you can have a look then @qtwrk

Viewing 15 replies - 1 through 15 (of 22 total)

The topic ‘Avoiding caching ActivityPub content’ is closed to new replies.