我有一个与API接口的插件,并将检索到的日程数据存储在transient.
将瞬态存储24小时:
set_transient($schedule_cache, $schedule_data, 60 * 60 * 24);
(我想)问题是:
它是为哪个存储24小时的?我想显示今天,但是如果瞬态设置为昨晚11点,当有人加载页面时,我们将在昨天显示到今晚11点。我正在使用的不雅观的方法是使用唯一的TODAY标识符存储第二个瞬态:
$this::$time_tracker = date(\'Fd\', strtotime("today")); # \'March30\'
set_transient($schedule_timer, $this::$time_tracker, 60 * 60 * 48);
然后,如果当前时间跟踪器与瞬态不匹配,则删除所有瞬态(还有其他用于分页的瞬态):if($last_look != $this::$time_tracker)
// Delete all the transients and save new ones
最小工作示例:class transientIssues {
public function __construct(){
$this::$time_tracker = date(\'Fd\', strtotime("today"));
}
$schedule_cache = \'sched_che\';
$schedule_timer = \'sched_tim\';
$last_look = get_transient($schedule_timer);
if ( $last_look != $this::$time_tracker ){
// delete_transient( $schedule_cache );
// Replaced above with the following so we could deal with multiple date ranges being called.
global $wpdb;
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE (\'%sched_ch%\' OR \'%sched_tim%\')" );
}
if ( false === get_transient( $schedule_cache ) ) {
$api = $this->instantiate_API();
if ($api == \'NO_SOAP_SERVICE\') {
pr($api);
}else{
$api->gettData();
}
set_transient($schedule_timer, $this::$time_tracker, 60 * 60 * 24);
set_transient($schedule_cache, $schedule_data, 60 * 60 * 24);
// END caching*/
}
}
这似乎是一种合理的方法吗?我欢迎提出见解。