mysql - wp_cache 是否仍然加载 Wordpress 并使用 MySQL?

标签 mysql wordpress

我有一个使用 wp_cache_set/wp_cache_get 来存储结果的 JSON API 端点。这个端点一天被命中数十万次。

然而,这经常会导致我的服务器宕机,因为缓存似乎仍在访问 MySQL 和/或加载 Wordpress。

这是真的吗?如果是的话,什么是更好的缓存解决方案来使它尽可能轻? (例如内存缓存)

--

以下是有用的代码:

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);

最佳答案

我最终使用 Cloudflare Page Rules 来缓存该特定 URL。干净简单 :)

关于mysql - wp_cache 是否仍然加载 Wordpress 并使用 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37331715/

相关文章:

css - CSS:不显示任何特定的CSS类

javascript - 将事件添加到 WordPress 插件联系表 7 中的复选框[]

mysql - 如何将 SHA1 和 MD5 文本值转换为二进制? (SQL)

MySQL:我无法执行脚本

wordpress - 如何创建wordpress标签同义词?

mysql - 查询从mysql数据库返回未在数据库表的列中列出的表

css - 在 Wordpress 中使用 html 和 sass

PHP表单刷新

MySQL。向数据库插入多个重复行

php - 高效的 friend 建议sql查询,无需使用php