Wordpress LScache Plugin: How to purge public cached URI programmatically?
Last Updated on: Wed, 15 Apr 2026 00:00:02 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/ , Im 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 1 year, 4 months ago by yaquawa. 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 senders IP must be in LiteSpeed WebServers allow list , or you can use --interface 127.0.0.1 , 127.0.0.1 should be automatically added into allow list Thanks @CacheCrawler ! 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. 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 @CacheCrawler may be its 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 ) Id like to purge the cache for /graphql?query=foo like this: do_action( litespeed_purge_url, foo ) is that possible? 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 Thanks @CacheCrawler Can you tell me when to use do_action( litespeed_tag_add, my-tag ) ? I mean it should be used in another hook right? when you generate a page that you want to put your own tag into like if URL = foo, then add tag bar fi
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference