Cache only one specific query string pattern

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Cache only one specific query string pattern

nginx mailing list
I use Wordpress’ REST API post feed to embed articles on an external site. My articles are updated fairly seldom, so there’s probably no need to dynamically compile every request response. I’m thinking of using fastcgi cache to cache the feed.

I’m currently skipping caching for all requests with a $query_string. However, the REST API URL’s also contain a query string and thus don’t currently get cached.

        if ($query_string != "") {
                set $skip_cache 1;
        }

Is it possible to cache the REST API URL’s but skip cache for all other URL’s containing a $query_string?


--
Palvelin.fi Hostmaster
[hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Cache only one specific query string pattern

nginx mailing list


> On 25 Sep 2018, at 16:35, Palvelin Postmaster via nginx <[hidden email]> wrote:
>
> I use Wordpress’ REST API post feed to embed articles on an external site. My articles are updated fairly seldom, so there’s probably no need to dynamically compile every request response. I’m thinking of using fastcgi cache to cache the feed.
>
> I’m currently skipping caching for all requests with a $query_string. However, the REST API URL’s also contain a query string and thus don’t currently get cached.
>
> if ($query_string != "") {
> set $skip_cache 1;
> }
>
> Is it possible to cache the REST API URL’s but skip cache for all other URL’s containing a $query_string?

In the absense of better suggestions, this seems to work. :)

# Wordpress-specific: URLs with a query string shouldn't be cached except when REST API
if ($request_uri ~ "^/wp-json/wp/v2/posts/.*") {
        set $cache_restapi "CACHE";
}

if ($query_string != "") {
        set $cache_restapi "${cache_restapi}NOT";
}

if ($cache_restapi = "NOT") {
        set $skip_cache 1;
}


--
Palvelin.fi Hostmaster
[hidden email]

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx