Wordpressで有効期限つきでキャッシュする

2015-06-18 13:28

Transients APIを使う。

$transient = 'name';
if (false === ( $data = get_transient($transient) ) ) {
	//期限切れ
	$data = 'result';
	set_transient($transient, $data, 60*60*1);
}

時間はWP3.5より下記定数が使える
MINUTE_IN_SECONDS = 60 (seconds)
HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS
DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS
WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS
YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS

Transients API



Category: WordPress

Tag: