我这样使用瞬态(简单示例):
function my_url_cache( $url )
{
$transient_id = hash( "crc32", $url );
$content = get_transient( \'my_url_cache_\' . $transient_id );
set_transient( \'my_url_cache_\' . $transient_id, $content, 60 * 60 * 24 );
set_transient( \'my_url_cache_backup_\' . $transient_id, $content, 0 );
}
与我公司的插件一起,当他们想要刷新缓存时,会出现以下错误:
对/wordpress/wp includes/cache中的非对象调用成员函数get()。php在线123
Without my plugin they have no problems
/wordpress/wp-includes/cache.php on line 123:
/**
* Retrieves the cache contents from the cache by key and group.
*
* @since 2.0.0
*
* @see WP_Object_Cache::get()
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
*
* @param int|string $key The key under which the cache contents are stored.
* @param string $group Optional. Where the cache contents are grouped. Default empty.
* @param bool $force Optional. Whether to force an update of the local cache from the persistent
* cache. Default false.
* @param bool $found Optional. Whether the key was found in the cache. Disambiguates a return of false,
* a storable value. Passed by reference. Default null.
* @return bool|mixed False on failure to retrieve contents or the cache
* contents on success
*/
function wp_cache_get( $key, $group = \'\', $force = false, &$found = null ) {
global $wp_object_cache;
return $wp_object_cache->get( $key, $group, $force, $found ); // Line 123
}
On my Testserver I cannot reproduce this error. 它们不使用不同的缓存系统。
$wp\\u object\\u缓存似乎不是对象。我不知道是我的插件还是他们的插件,还是两者兼而有之。
Do I have to use a special hook in Wordpress, 在使用get\\uu和set\\u瞬态函数之前?我仅在此挂钩内使用缓存函数:
add_shortcode( \'feedimport\', array( $this, "shortcode_feedimport" ) );
UPDATE:
另一个插件使用wp\\u schedule\\u事件:
private static function cron_schedule_event_setup() {
wp_clear_scheduled_hook(self::cron_hook);
wp_schedule_event(time(), self::$options[\'schedule_event\'], self::cron_hook);
}
并将其数据存储在数据库表中。它们不使用get\\uSet\\u瞬态函数:(
我真的不知道我的插件会如何影响他们的插件。插件的完整代码:link
Update 2 - Solved:
public function __destruct() {
$this->save_log();
}
这段代码启动了一个使用wordpress缓存系统的函数。
更改为:
add_action(\'shutdown\', array($this, "save_log"));
解决了问题。我从来没有在析构函数中再次使用Wordpress函数。