admin管理员组文章数量:1310325
Working with transients with a timeout, I seem to be getting two transients created, and I don't quite understand why. Looking at the source code on: /, it would appear this only occurs when wp_using_ext_object_cache() returns false.
My calls are:
set_transient( 'mytransientprefix_key', 'value', 3600);
and then I update the same transient with:
set_transient( 'mytransientprefix_key', 'new_value', 3600);
In the wp_options table, I'm then left with:
One _transient_timeout_mytransientprefix_key ("value") and one _transient_mytransientprefix_key ("new_value").
What?
Working with transients with a timeout, I seem to be getting two transients created, and I don't quite understand why. Looking at the source code on: https://developer.wordpress/reference/functions/set_transient/, it would appear this only occurs when wp_using_ext_object_cache() returns false.
My calls are:
set_transient( 'mytransientprefix_key', 'value', 3600);
and then I update the same transient with:
set_transient( 'mytransientprefix_key', 'new_value', 3600);
In the wp_options table, I'm then left with:
One _transient_timeout_mytransientprefix_key ("value") and one _transient_mytransientprefix_key ("new_value").
What?
Share Improve this question asked Jan 20, 2021 at 10:47 johojoho 634 bronze badges 1 |1 Answer
Reset to default 6Why WordPress creates two transients: Because the first transient with timeout
in the name, is used for storing the expiration you set for your transient (but the stored value is a UNIX timestamp, not simply the value you passed like 3600
) so that WordPress knows when to delete your transient. As for the second one, it stores the actual transient value that you passed to set_transient()
, i.e. the second parameter.
$key = 'mytransientprefix_key';
set_transient( $key, 'value', 3600 );
// That will create two options:
// _transient_timeout_mytransientprefix_key and
// _transient_mytransientprefix_key
var_dump(
get_option( '_transient_timeout_' . $key ),
get_option( '_transient_' . $key )
);
// Sample output: int(1611143902) string(5) "value"
So the value of the "timeout" transient shouldn't be value
— try the above code and see how it goes?
版权声明:本文标题:plugin development - Why does WordPress create two transients with the same name when I specify timeout value? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741819531a2399282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
_timeout_
one ought to a unix timestamp for now + 3600, not 'value'. Is it definitely 'value'? – Rup Commented Jan 20, 2021 at 10:50