By default, Sunny perform a purge whenever a post being edited. Manually triggering purges is usually unnecessary.
If you must, trigger a edit_post event is the easiest option. See: https://developer.ww.wp.xz.cn/reference/hooks/edit_post/
If edit_post’s side effects cause troubles, there is a rest endpoint for you: https://github.com/TypistTech/sunny/blob/master/src/REST/Controllers/Posts/Caches/DeleteController.php
Thread Starter
pdku
(@pdku)
so what i want is add a button in my post , so when i click at that button , it will clear cache for that post only , is that possible ?
Possible but not an easy task.
$reason = 'Some string';
$nullTargets = new Targets([]);
$urls = ['https://example.com/abc'];
$purgeCommand = new PurgeCommand($reason, $nullTargets, $urls);
Then you have to build/get the Purger instance and run execute:
$purger->execute($purgeCommand);
Build the Purger instance manually is not an easy task. Get it from Sunny’s container is a better choice. See https://github.com/typisttech/sunny#extending-sunny
—
Sunny doesn’t expect you to purge single url only because I believe purging more urls doesn’t hurt whereas purging less urls usually causes troubles.
What is your use case of purging single url but not its related urls?
If you have a strong reason to purge one single url and don’t mind skipping all the hooks and filters, invoke the api client directly: https://github.com/TypistTech/sunny/blob/master/src/Api/Cache.php
-
This reply was modified 8 years, 2 months ago by
Tang Rufus.
Thread Starter
pdku
(@pdku)
im runggin a streaming site , so sometimes when the video error or i change the subtitles it doesnt automatically change because cloudflare still cached it , so the visitors can do purge the cache themself
Thread Starter
pdku
(@pdku)
can you build that for me , the code will be put on posts.php the function is a button/text when click it will purge that post url cache , i will make some donation for you sir if you can.
wp.org forum doesn’t allow offer to work for hire – https://make.ww.wp.xz.cn/support/handbook/forum-welcome/#do-not-offer-to-work-for-hire
I won’t work on something free of charge and then wait for donation.
Hiring a freelance developer is your best option.