• Resolved HolaEffect

    (@holaeffect)


    I’m looking for a way to exclude specific items from the cache (in this case, never caching posts if the posts have a specific category).

    Some posts will show an excerpt for non-members and the full post for members. Hence, we can’t cache serve the same version of the post to everybody.

    How do I do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Acato

    (@acato)

    Hi @holaeffect

    Thank you for using our plugin!

    We are working on a new feature where you can have certain request headers be used to distinguish between seperate caches, maybe that can help?

    Until that feature is released there are some possible fixes:

    I know these aren’t really nice solutions, so please let me know if the feature I described (about using request headers to distinguish between seperate caches) can help you. Because if it cannot help you maybe we can think of a different solution we could implement.

    Thread Starter HolaEffect

    (@holaeffect)

    Could you give an example of how the request headers to distinguish between separate caches would work in practice?

    And, ideally what I would like is to just add some code, server side, that prevents certain items from being cached. The same way you can now add or exclude endpoints from caching, I would like to be able to do the same, but on the item level. E.g. by object ID.

    Plugin Author Acato

    (@acato)

    Hi @holaeffect

    It is still a work in progress and we are brainstorming how it should actually work / where you can do the settings exactly), but the general idea is this:

    In the settings of the plugin you can set which request headers should be used (or possibly via a hook so you can set it per endpoint).

    So if for instance you are sending a header WPLANG (to set which language should be returned), you then set it as cacheable header. And each time you do a request to the WP REST API, the caching plugin will check if there is already a cache record for the requested url combined with the correct WPLANG header.
    So a call to /wp-json/wp/v2/posts with request header WPLANG set to en_US will result in a different cache than a call to the same url /wp-json/wp/v2/posts but with the request header WPLANG set to nl_NL.

    What you want could be quite hard (maybe even impossible) to implement correctly. You want specific items not to be cached. But what if that item is one of the items returned by the /wp-json/wp/v2/posts endpoint? That would mean we cannot cache that endpoint at all?
    I am going to think about it a bit more, to see if maybe we can come up with a workable solution for this.

    Plugin Author Acato

    (@acato)

    Hi @holaeffect

    We just released a new version of our plugin, which includes the implementation of the caching based upon request headers. See this FAQ entry for more details.

    Please let us kno if this solves your problem.

    Plugin Author Acato

    (@acato)

    This thread has been marked as resolved due to lack of activity.

    You’re always welcome to open a new topic.

    Thanks for understanding!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to exclude specific items’ is closed to new replies.