How to clear cache of a json file in my Godaddy Wordpress website automatically when I update it

33 Views Asked by At

So I have a website hosted on Godaddy, where I have a "sellers.json" file, the file updates once in a while using a php script I created to update the phpmyadmin database, all of the CRUD operations work as they should, however, the issue we encounter is that on every database update I have to manually go into /wp-admin and click flush cache.

As a developer, I wanted to create a function that will automaticly flush the cache upon every create/edit/delete, I have came across this function "WP_Object_Cache::flush()", and tried to use it but it didn't work for me due to an error. Is that the function and method that I need? or is there an easier method?

1

There are 1 best solutions below

3
Theodore R. Smith On

Your question is definitely incomplete, and it's going to be hard to find a legit answer.

How do you experience the cached file? I'm assuming that it is downloaded via https:// on the website? That's really the only time WordPress and cache is involved...

So the answer is to rewrite the URL code inside to do this:

$filePath = "/location/on/fs/of/sellers.json";
$fileURI = "/location/on/uri/sellers.json";
$timestamp = filemtime($filePath);
echo "<a href=\"$fileURI?$timestamp\">My Sellers</a>";

The trick is to pass a timestamp of the file with the URL. Then, you'll never need to hit the clear-cache button.