本文整理汇总了PHP中wp_using_ext_object_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_using_ext_object_cache函数的具体用法?PHP wp_using_ext_object_cache怎么用?PHP wp_using_ext_object_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_using_ext_object_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
if (wp_using_ext_object_cache()) {
$this->markTestSkipped('Not testable with an external object cache.');
}
}
示例2: delete_version_transients
/**
* When the transient version increases, this is used to remove all past transients to avoid filling the DB.
*
* Note; this only works on transients appended with the transient version, and when object caching is not being used.
*
* @since 2.3.10
*/
private static function delete_version_transients($version)
{
if (!wp_using_ext_object_cache() && !empty($version)) {
global $wpdb;
$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name LIKE %s;", "\\_transient\\_%" . $version));
}
}
示例3: wc_delete_product_transients
/**
* Clear all transients cache for product data.
*
* @param int $post_id (default: 0)
*/
function wc_delete_product_transients($post_id = 0)
{
global $wpdb;
if (wp_using_ext_object_cache()) {
wp_cache_flush();
// There isn't a reliable method of looking up the names, so flush the cache.
return;
}
$post_id = absint($post_id);
// Clear core transients
$transients_to_clear = array('wc_products_onsale', 'wc_hidden_product_ids', 'wc_hidden_product_ids_search', 'wc_attribute_taxonomies', 'wc_term_counts', 'wc_featured_products');
// Clear transients for which we don't have the name
$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%')");
$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%')");
$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')");
$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE ('_transient_wc_products_will_display_%') OR `option_name` LIKE ('_transient_timeout_wc_products_will_display_%')");
// Clear product specific transients
$post_transient_names = array('wc_product_children_ids_', 'wc_product_total_stock_', 'wc_average_rating_', 'wc_rating_count_');
if ($post_id > 0) {
foreach ($post_transient_names as $transient) {
$transients_to_clear[] = $transient . $post_id;
}
} else {
foreach ($post_transient_names as $transient) {
$wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE %s OR `option_name` LIKE %s", '_transient_' . $transient . '%', '_transient_timeout_' . $transient . '%'));
}
}
// Delete transients
foreach ($transients_to_clear as $transient) {
delete_transient($transient);
}
do_action('woocommerce_delete_product_transients', $post_id);
}
示例4: process
public function process()
{
global $wp_object_cache;
$this->data['ext_object_cache'] = (bool) wp_using_ext_object_cache();
if (is_object($wp_object_cache)) {
if (isset($wp_object_cache->cache_hits)) {
$this->data['stats']['cache_hits'] = $wp_object_cache->cache_hits;
}
if (isset($wp_object_cache->cache_misses)) {
$this->data['stats']['cache_misses'] = $wp_object_cache->cache_misses;
}
if (isset($wp_object_cache->stats)) {
foreach ($wp_object_cache->stats as $key => $value) {
if (!is_scalar($value)) {
continue;
}
$this->data['stats'][$key] = $value;
}
}
}
if (isset($this->data['stats']['cache_hits']) && isset($this->data['stats']['cache_misses'])) {
$total = $this->data['stats']['cache_misses'] + $this->data['stats']['cache_hits'];
$this->data['cache_hit_percentage'] = 100 / $total * $this->data['stats']['cache_hits'];
}
}
示例5: delete_cache_value
private static function delete_cache_value($group)
{
if (!wp_using_ext_object_cache()) {
global $wpdb;
$sql = "\n\t\t\t\tdelete from {$wpdb->options}\n\t\t\t\twhere option_name like '_transient_{$group}%' or option_name like '_transient_timeout_{$group}%'\n\t\t\t";
return $wpdb->query($sql);
}
return false;
}
示例6: delete_product_query_transients
/**
* Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
*/
public static function delete_product_query_transients()
{
// Increments the transient version to invalidate cache
WC_Cache_Helper::get_transient_version('product_query', true);
// If not using an external caching system, we can clear the transients out manually and avoid filling our DB
if (!wp_using_ext_object_cache()) {
global $wpdb;
$wpdb->query("\n\t\t\t\tDELETE FROM `{$wpdb->options}`\n\t\t\t\tWHERE `option_name` LIKE ('\\_transient\\_wc\\_uf\\_pid\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_timeout\\_wc\\_uf\\_pid\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_wc\\_products\\_will\\_display\\_%')\n\t\t\t\tOR `option_name` LIKE ('\\_transient\\_timeout\\_wc\\_products\\_will\\_display\\_%')\n\t\t\t");
}
}
示例7: _get_cron_lock
function _get_cron_lock()
{
global $wpdb;
$value = 0;
if (wp_using_ext_object_cache()) {
// Skip local cache and force refetch of doing_cron transient in case
// another processs updated the cache
$value = wp_cache_get('doing_cron', 'transient', true);
} else {
$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", '_transient_doing_cron'));
if (is_object($row)) {
$value = $row->option_value;
}
}
return $value;
}
示例8: delete_user_transient
/**
* Delete a user transient
*
* @param \WP_User|int $user
* @param string $transient
*
* @return bool
*/
public static final function delete_user_transient($user, $transient)
{
$user = $user instanceof \WP_User ?: new \WP_User($user);
do_action('delete_user_transient_' . $transient, $transient, $user->ID);
if (wp_using_ext_object_cache()) {
$result = wp_cache_delete("{$transient}-{$user->ID}", 'user_transient');
} else {
$result = delete_user_meta($user->ID, "_transient_{$transient}");
if ($result) {
delete_user_meta($user->ID, "_transient_timeout_{$transient}");
}
}
if ($result) {
do_action('deleted_user_transient', $transient);
}
return $result;
}
示例9: __construct
/**
* Register the allowed routes.
* @param \Slim\Slim $app
*/
public function __construct(\Slim\Slim $app)
{
parent::__construct($app);
$this->registerRoute('GET', 'posts/?', array(__NAMESPACE__ . '\\controllers\\Posts', 'find'));
$this->registerRoute('GET', 'posts/:id/?', array(__NAMESPACE__ . '\\controllers\\Posts', 'findById'));
$this->registerRoute('GET', 'posts/:id/comments/?', array(__NAMESPACE__ . '\\controllers\\Comments', 'findByPost'));
$this->registerRoute('GET', 'users/?', array(__NAMESPACE__ . '\\controllers\\Users', 'find'));
$this->registerRoute('GET', 'users/:id/?', array(__NAMESPACE__ . '\\controllers\\Users', 'findById'));
$this->registerRoute('GET', 'taxonomies/?', array(__NAMESPACE__ . '\\controllers\\Taxonomies', 'find'));
$this->registerRoute('GET', 'taxonomies/:name/?', array(__NAMESPACE__ . '\\controllers\\Taxonomies', 'findById'));
$this->registerRoute('GET', 'taxonomies/:taxonomy_name/terms/?', array(__NAMESPACE__ . '\\controllers\\Terms', 'find'));
$this->registerRoute('GET', 'taxonomies/:taxonomy_name/terms/:term_id/?', array(__NAMESPACE__ . '\\controllers\\Terms', 'findById'));
$this->registerRoute('GET', 'rewrite_rules/?', array(__NAMESPACE__ . '\\controllers\\RewriteRules', 'find'));
$this->registerRoute('GET', 'comments/?', array(__NAMESPACE__ . '\\controllers\\Comments', 'find'));
$this->registerRoute('GET', 'comments/:id?', array(__NAMESPACE__ . '\\controllers\\Comments', 'findById'));
if (function_exists('wp_using_ext_object_cache') && wp_using_ext_object_cache()) {
//add filters for last-modified based off of the 'last_changed' caching in core
$filter_last_post_mod = function ($last_modified) {
if ($last_changed = wp_cache_get('last_changed', 'posts')) {
list($micro, $time) = explode(' ', $last_changed);
$last_modified = gmdate('Y-m-d H:i:s', $time);
}
return $last_modified;
};
add_filter('thermal_get_lastpostmodified', $filter_last_post_mod);
$filter_last_comment_mod = function ($last_modified) {
if ($last_changed = wp_cache_get('last_changed', 'comments')) {
list($micro, $time) = explode(' ', $last_changed);
$last_modified = gmdate('Y-m-d H:i:s', $time);
}
return $last_modified;
};
add_filter('thermal_get_lastcommentmodified', $filter_last_comment_mod);
add_filter('thermal_comment_last_modified', $filter_last_comment_mod);
$filter_last_term_mod = function ($last_modified) {
if ($last_changed = wp_cache_get('last_changed', 'terms')) {
list($micro, $time) = explode(' ', $last_changed);
$last_modified = gmdate('Y-m-d H:i:s', $time);
}
return $last_modified;
};
add_filter('thermal_get_lasttermmodified', $filter_last_term_mod);
add_filter('thermal_term_last_modified', $filter_last_term_mod);
}
}
示例10: bp_rbe_get_setting
/**
* Get an individual setting from RBE's settings array.
*
* @since 1.0-RC3
*
* @param string $setting The setting parameter.
* @param array $args {
* Misc settings.
* @type bool $refetch Whether to refetch RBE's settings. Handy when you
* need to ensure the settings are updated. Defaults to false.
* }
* @return string|bool
*/
function bp_rbe_get_setting($setting = '', $args = array())
{
if (empty($setting) || !is_string($setting)) {
return false;
}
$r = wp_parse_args($args, array('refetch' => false));
global $bp_rbe;
// refetches RBE options
if (true === $r['refetch']) {
// flush cache if necessary
if (!wp_using_ext_object_cache()) {
wp_cache_flush();
}
// refetch option
$bp_rbe->settings = bp_get_option('bp-rbe');
}
return isset($bp_rbe->settings[$setting]) ? $bp_rbe->settings[$setting] : false;
}
示例11: set_site_transient
/**
* Set/update the value of a site transient.
*
* You do not need to serialize values, if the value needs to be serialize, then
* it will be serialized before it is set.
*
* @since 2.9.0
*
* @see set_transient()
*
* @param string $transient Transient name. Expected to not be SQL-escaped. Must be
* 40 characters or fewer in length.
* @param mixed $value Transient value. Expected to not be SQL-escaped.
* @param int $expiration Optional. Time until expiration in seconds. Default 0.
* @return bool False if value was not set and true if value was set.
*/
function set_site_transient($transient, $value, $expiration = 0)
{
/**
* Filter the value of a specific site transient before it is set.
*
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
*
* @since 3.0.0
* @since 4.4.0 The `$transient` parameter was added
*
* @param mixed $value Value of site transient.
* @param string $transient Transient name.
*/
$value = apply_filters('pre_set_site_transient_' . $transient, $value, $transient);
$expiration = (int) $expiration;
if (wp_using_ext_object_cache()) {
$result = wp_cache_set($transient, $value, 'site-transient', $expiration);
} else {
$transient_timeout = '_site_transient_timeout_' . $transient;
$option = '_site_transient_' . $transient;
if (false === get_network_option($option)) {
if ($expiration) {
add_network_option($transient_timeout, time() + $expiration);
}
$result = add_network_option($option, $value);
} else {
if ($expiration) {
update_network_option($transient_timeout, time() + $expiration);
}
$result = update_network_option($option, $value);
}
}
if ($result) {
/**
* Fires after the value for a specific site transient has been set.
*
* The dynamic portion of the hook name, `$transient`, refers to the transient name.
*
* @since 3.0.0
* @since 4.4.0 The `$transient` parameter was added
*
* @param mixed $value Site transient value.
* @param int $expiration Time until expiration in seconds. Default 0.
* @param string $transient Transient name.
*/
do_action('set_site_transient_' . $transient, $value, $expiration, $transient);
/**
* Fires after the value for a site transient has been set.
*
* @since 3.0.0
*
* @param string $transient The name of the site transient.
* @param mixed $value Site transient value.
* @param int $expiration Time until expiration in seconds. Default 0.
*/
do_action('setted_site_transient', $transient, $value, $expiration);
}
return $result;
}
示例12: testGetTermLastModified
public function testGetTermLastModified()
{
if (!function_exists('wp_using_ext_object_cache')) {
return;
}
//temporarily turn on object cache since no core methods provide last modified for terms without caching enabled
$tmp = wp_using_ext_object_cache();
wp_using_ext_object_cache(true);
$testdata = $this->_insertTestData();
list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/taxonomies/public_taxonomy_a/terms/' . $testdata['term_a']['term_id'], 'QUERY_STRING' => ''));
$data = json_decode($body);
$this->assertEquals('200', $status);
$this->assertNotEmpty($headers['last-modified']);
$last_modified = $headers['last-modified'];
list($status, $headers, $body) = $this->_getResponse(array('REQUEST_METHOD' => 'GET', 'PATH_INFO' => Voce\Thermal\get_api_base() . 'v1/taxonomies/public_taxonomy_a/terms/' . $testdata['term_a']['term_id'], 'QUERY_STRING' => '', 'IF_MODIFIED_SINCE' => $last_modified));
$this->assertEquals('304', $status);
$this->assertEmpty($body);
wp_using_ext_object_cache($tmp);
}
示例13: output
function output($section_name, $config, $options, $return = false, $withoptions = false)
{
/*
* Cache busting
*/
if (function_exists('wp_using_ext_object_cache')) {
wp_using_ext_object_cache(false);
}
$uid = 'vp_' . md5(serialize(func_get_args()));
if (false === ($data = get_transient('mod_' . $uid))) {
$data = op_sl_parse('video_player', array('section_name' => $section_name, 'config' => $config, 'options' => $options, 'use_controls' => $this->use_controls, 'player_count' => $this->player_count));
if (is_string($data) && 0 === strpos($data, '##')) {
$data = substr($data, 2);
} elseif (!empty($data)) {
set_transient('mod_' . $uid, $data, OP_SL_ELEMENT_CACHE_LIFETIME);
} else {
$data = array('use_controls' => $this->use_controls, 'player_count' => $this->player_count, 'out' => '', 'new_options' => array());
}
}
if (isset($data['use_controls'])) {
$this->use_controls = $data['use_controls'];
}
if (isset($data['player_count'])) {
$this->player_count = $this->player_count + (int) $data['player_count'];
}
/*
* Cache busting
*/
if (function_exists('wp_using_ext_object_cache')) {
wp_using_ext_object_cache(true);
}
if ($return) {
return $withoptions ? array('output' => $data['out'], 'options' => $data['new_options']) : $data['out'];
}
echo $data['out'];
}
示例14: getPluggableFunctionSignatures
/**
* Expected pluggable function signatures.
*
* @return array Array of signatures keyed by their function name.
*/
public function getPluggableFunctionSignatures()
{
$signatures = array('wp_set_current_user' => array('id', 'name' => ''), 'wp_get_current_user' => array(), 'get_userdata' => array('user_id'), 'get_user_by' => array('field', 'value'), 'cache_users' => array('user_ids'), 'wp_mail' => array('to', 'subject', 'message', 'headers' => '', 'attachments' => array()), 'wp_authenticate' => array('username', 'password'), 'wp_logout' => array(), 'wp_validate_auth_cookie' => array('cookie' => '', 'scheme' => ''), 'wp_generate_auth_cookie' => array('user_id', 'expiration', 'scheme' => 'auth', 'token' => ''), 'wp_parse_auth_cookie' => array('cookie' => '', 'scheme' => ''), 'wp_set_auth_cookie' => array('user_id', 'remember' => false, 'secure' => '', 'token' => ''), 'wp_clear_auth_cookie' => array(), 'is_user_logged_in' => array(), 'auth_redirect' => array(), 'check_admin_referer' => array('action' => -1, 'query_arg' => '_wpnonce'), 'check_ajax_referer' => array('action' => -1, 'query_arg' => false, 'die' => true), 'wp_redirect' => array('location', 'status' => 302), 'wp_sanitize_redirect' => array('location'), '_wp_sanitize_utf8_in_redirect' => array('matches'), 'wp_safe_redirect' => array('location', 'status' => 302), 'wp_validate_redirect' => array('location', 'default' => ''), 'wp_notify_postauthor' => array('comment_id', 'deprecated' => null), 'wp_notify_moderator' => array('comment_id'), 'wp_password_change_notification' => array('user'), 'wp_new_user_notification' => array('user_id', 'deprecated' => null, 'notify' => ''), 'wp_nonce_tick' => array(), 'wp_verify_nonce' => array('nonce', 'action' => -1), 'wp_create_nonce' => array('action' => -1), 'wp_salt' => array('scheme' => 'auth'), 'wp_hash' => array('data', 'scheme' => 'auth'), 'wp_hash_password' => array('password'), 'wp_check_password' => array('password', 'hash', 'user_id' => ''), 'wp_generate_password' => array('length' => 12, 'special_chars' => true, 'extra_special_chars' => false), 'wp_rand' => array('min' => 0, 'max' => 0), 'wp_set_password' => array('password', 'user_id'), 'get_avatar' => array('id_or_email', 'size' => 96, 'default' => '', 'alt' => '', 'args' => null), 'wp_text_diff' => array('left_string', 'right_string', 'args' => null), 'install_network' => array(), 'wp_install' => array('blog_title', 'user_name', 'user_email', 'public', 'deprecated' => '', 'user_password' => '', 'language' => ''), 'wp_install_defaults' => array('user_id'), 'wp_new_blog_notification' => array('blog_title', 'blog_url', 'user_id', 'password'), 'wp_upgrade' => array(), 'install_global_terms' => array());
// Pluggable function signatures are not tested when an external object cache is in use. #31491
if (!wp_using_ext_object_cache()) {
$signatures = array_merge($signatures, array('wp_cache_add' => array('key', 'data', 'group' => '', 'expire' => 0), 'wp_cache_close' => array(), 'wp_cache_decr' => array('key', 'offset' => 1, 'group' => ''), 'wp_cache_delete' => array('key', 'group' => ''), 'wp_cache_flush' => array(), 'wp_cache_get' => array('key', 'group' => '', 'force' => false, 'found' => null), 'wp_cache_incr' => array('key', 'offset' => 1, 'group' => ''), 'wp_cache_init' => array(), 'wp_cache_replace' => array('key', 'data', 'group' => '', 'expire' => 0), 'wp_cache_set' => array('key', 'data', 'group' => '', 'expire' => 0), 'wp_cache_switch_to_blog' => array('blog_id'), 'wp_cache_add_global_groups' => array('groups'), 'wp_cache_add_non_persistent_groups' => array('groups'), 'wp_cache_reset' => array()));
}
return $signatures;
}
示例15: invalidate_storage
/**
* Invalidate sitemap cache
*
* @param null|string $type The type to get the key for. Null for all caches.
*
* @return void
*/
public static function invalidate_storage($type = null)
{
// Global validator gets cleared when no type is provided.
$old_validator = null;
// Get the current type validator.
if (!is_null($type)) {
$old_validator = self::get_validator($type);
}
// Refresh validator.
self::create_validator($type);
if (!wp_using_ext_object_cache()) {
// Clean up current cache from the database.
self::cleanup_database($type, $old_validator);
}
// External object cache pushes old and unretrieved items out by itself so we don't have to do anything for that.
}