Ten*_*eno 0 php wordpress wordpress-plugin
有没有办法在检索整个保存的数据之前检查瞬态是否存在?
根据此页面http://codex.wordpress.org/Transients_API,要检查是否已成功检索保存的瞬态值,请使用以下代码:
if ( false === ( $value = get_transient( 'value' ) ) ) {
// this code runs when there is no valid transient set
}
Run Code Online (Sandbox Code Playgroud)
但是假设如果可用,将使用检索到的数据.当使用Transient API缓存数百个网页并且仅在缓存仍然存在时才需要检查,检索所有数据是不切实际的.我不确定它是如何影响速度和内存的,但一般来说,尺寸越大,速度越慢,消耗的内存就越多.
所以我想知道是否有一种简单的方法来检查它是否被保存或者不像empty()函数一样.
感谢你的信息.
小智 5
这只会检索到期时间.
$your_transient = 'your_transient';
$data_timeout = get_option('_transient_timeout_' . $your_transient);
if ($data_timeout < time())
echo 'it is expired.';
else
echo 'there is a transient';
Run Code Online (Sandbox Code Playgroud)