I have a JSON API endpoint that uses wp_cache_set/wp_cache_get to store the result. This endpoint is hit hundreds of thousands of times in a day.
However this often takes down my server as it seems the cache is still accessing MySQL and/or loading Wordpress.
Is this true? And if so what would be a better caching solution to make this as light as possible? (eg. memcached)
--
Here's code in case that's helpful:
define('WP_USE_THEMES', false);
require_once('../../../wp-blog-header.php');
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
if(!$image_url) $image_url = $_GET['url'];
if(!$image_url) return false;
$cacheTitle = md5($image_url) . '1';
$result = wp_cache_get( $cacheTitle );
$notCached = $result ? false : true;
if ($notCached){
/** Insert code here to get the data I need and store it in $result **/
wp_cache_set( $cacheTitle, $result );
}
return json_encode($result);