• Resolved yaquawa

    (@yaquawa)


    I have set the public cache URI to “^/graphql”, which make it cache any GET requests that match the pattern “^/graphql”.

    For example:

    GET https://example.com/graphql?query=foo
    GET https://example.com/graphql?query=bar
    GET https://example.com/graphql?query=foobar

    What I want to do is that purging specific cache for example the cache for GET https://example.com/graphql?query=foo after a specific post has been saved.

    Currently, to purge the cache for “^/graphql?query=XXX” I have to do a “purge all” action, which is not what I want, that purges too much…
    I want to purge the cache for specific URI programmatically.

    I have read https://docs.litespeedtech.com/lscache/lscwp/api/ , I’m sure it can be achieved by utilizing the hooks some how… could you show me some sample code for implementing this? Thanks!

    • This topic was modified 3 years, 7 months ago by yaquawa.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support qtwrk

    (@qtwrk)

    you can try :

    do_action( 'litespeed_purge_url', '/graphql?query=foo' ); via LSCWP API

    header('x-litespeed-purge:/graphql?query=foo'); via PHP header() function ( LSCWP itself may send header, you may need to add second arugment false into it as well. )

    curl -XPURGE -I https://example.com/graphql?query=foo via command line curl , the sender’s IP must be in LiteSpeed WebServer’s allow list , or you can use --interface 127.0.0.1 , 127.0.0.1 should be automatically added into allow list

    Thread Starter yaquawa

    (@yaquawa)

    Thanks @qtwrk !
    So the cache key is the path of the URL right? Can I set the cache key myself? For example set the cache key foo for GET https://example.com/graphql?query=foo.

    Plugin Support qtwrk

    (@qtwrk)

    not sure what do you mean by “cache key” in this context

    LiteSpeed Cache is URL-based caching system , in combine with tags

    each URI will have its on cache

    
    /graphql?query=foo
    /graphql?query=bar
    

    these will be 2 caches

    Thread Starter yaquawa

    (@yaquawa)

    @qtwrk may be it’s the “cache tag”(https://docs.litespeedtech.com/lscache/lscwp/api/#final-tagging) in the context of LiteSpeed Cache ?

    I mean, instead of doing:
    do_action( 'litespeed_purge_url', '/graphql?query=foo' );

    I’d like to purge the cache for /graphql?query=foo like this:
    do_action( 'litespeed_purge_url', 'foo' );

    is that possible?

    • This reply was modified 3 years, 7 months ago by yaquawa.
    Plugin Support qtwrk

    (@qtwrk)

    in that case, you need to attach the tag beforehand

    e.g.

    do_action( 'litespeed_tag_add', 'my-tag' );

    and then you can use

    do_action( 'litespeed_purge', 'my-tag' );

    to purge it

    the tag can be repeatedly used across many pages , and when you call purge , it will purge all pages that contains this tag

    Thread Starter yaquawa

    (@yaquawa)

    Thanks @qtwrk

    Can you tell me when to use do_action( 'litespeed_tag_add', 'my-tag' ) ?
    I mean it should be used in another hook right?

    Plugin Support qtwrk

    (@qtwrk)

    when you generate a page that you want to put your own tag into

    like

    if URL = foo, then
    add tag bar
    fi

    • This reply was modified 3 years, 7 months ago by qtwrk.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to purge “public cached URI” programmatically?’ is closed to new replies.