Ajax 使用外部API在Wordpress网站上显示产品部分
我需要使用另一个API在Wordpress网站上显示以下部分:Ajax 使用外部API在Wordpress网站上显示产品部分,ajax,wordpress,performance,api,transient,Ajax,Wordpress,Performance,Api,Transient,我需要使用另一个API在Wordpress网站上显示以下部分: 产品搜索 带分页的产品列表 流行产品 物料组 类别及小类别组 同类产品 我们有大约5页与本节相关 我计划用ajax、wp_remote_get()和TLC瞬态实现这一点 a) 我们必须在网站上显示大量数据。因此,它会将瞬态(大量数据)添加到选项表中。这会影响站点性能吗 b) 我们是否应该使用瞬变清洁剂来清除过期的TLC瞬变 c) 即使在过期时间之后,更改API URL中的限制也不会反映在瞬态数据中。这需要时间吗?这是一个已知的问题吗
function test_tlc_transient() {
$t = tlc_transient( 'popular-products' )
->expires_in( 300 )
//->background_only()
->updates_with( 'sample_fetch_and_append', array( 'http://siteurl/restapi/frontend/GetMostProductViewed?start=0&limit=12' ) )
->get();
var_dump( $t );
if ( !$t )
echo "The request is false, because it isn't yet in the cache. It'll be there in about 10 seconds. Keep refreshing!";
}
function sample_fetch_and_append( $url ) {
$f = wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 30 ) ) );
return $f;
}
d) 我们有没有更好的替代方案来实现这一点
谢谢