本文整理汇总了PHP中wp_cache_incr函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_incr函数的具体用法?PHP wp_cache_incr怎么用?PHP wp_cache_incr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_incr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batcache_clear_url
function batcache_clear_url($url)
{
global $batcache, $wp_object_cache;
if (empty($url)) {
return false;
}
if (0 === strpos($url, 'https://')) {
$url = str_replace('https://', 'http://', $url);
}
if (0 !== strpos($url, 'http://')) {
$url = 'http://' . $url;
}
$url_key = md5($url);
wp_cache_add("{$url_key}_version", 0, $batcache->group);
$retval = wp_cache_incr("{$url_key}_version", 1, $batcache->group);
$batcache_no_remote_group_key = array_search($batcache->group, (array) $wp_object_cache->no_remote_groups);
if (false !== $batcache_no_remote_group_key) {
// The *_version key needs to be replicated remotely, otherwise invalidation won't work.
// The race condition here should be acceptable.
unset($wp_object_cache->no_remote_groups[$batcache_no_remote_group_key]);
$retval = wp_cache_set("{$url_key}_version", $retval, $batcache->group);
$wp_object_cache->no_remote_groups[$batcache_no_remote_group_key] = $batcache->group;
}
return $retval;
}
示例2: batcache_clear_url
function batcache_clear_url($url)
{
global $batcache;
if (empty($url)) {
return false;
}
$url_key = md5($url);
wp_cache_add("{$url_key}_version", 0, $batcache->group);
return wp_cache_incr("{$url_key}_version", 1, $batcache->group);
}
示例3: wpcom_vip_login_limiter
function wpcom_vip_login_limiter($username)
{
$ip = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
$key1 = $ip . '|' . $username;
// IP + username
$key2 = $ip;
// IP only
// Longer TTL when logging in as admin, which we don't allow on WP.com
wp_cache_add($key1, 0, 'login_limit', 'admin' == $username ? HOUR_IN_SECONDS : MINUTE_IN_SECONDS * 5);
wp_cache_add($key2, 0, 'login_limit', HOUR_IN_SECONDS);
wp_cache_incr($key1, 1, 'login_limit');
wp_cache_incr($key2, 1, 'login_limit');
}
示例4: check_lock
/**
* Set a lock and limit how many concurrent jobs are permitted
*
* @param $lock string Lock name
* @param $limit int Concurrency limit
* @param $timeout int Timeout in seconds
*
* @return bool
*/
public static function check_lock($lock, $limit = null, $timeout = null)
{
// Timeout, should a process die before its lock is freed
if (!is_numeric($timeout)) {
$timeout = LOCK_DEFULT_TIMEOUT_IN_MINUTES * \MINUTE_IN_SECONDS;
}
// Check for, and recover from, deadlock
if (self::get_lock_timestamp($lock) < time() - $timeout) {
self::reset_lock($lock);
return true;
}
// Default limit for concurrent events
if (!is_numeric($limit)) {
$limit = LOCK_DEFAULT_LIMIT;
}
// Check if process can run
if (self::get_lock_value($lock) >= $limit) {
return false;
} else {
wp_cache_incr(self::get_key($lock));
return true;
}
}
示例5: flush_group_cache
/**
* Increment the number stored with group name as key.
*/
public function flush_group_cache()
{
wp_cache_incr('current_key_index', 1, $this->group);
}
示例6: batcache_flush_all
/**
* Increment the batcache group incrementor value, invalidating the cache.
* @return false|int False on failure, the item's new value on success.
*/
function batcache_flush_all()
{
return wp_cache_incr('cache_incrementors', 1, 'batcache');
}
示例7: update_views_using_cache
/**
* update_views_using_cache
*
*
* @return
* @version 1.0.2
*
*/
private static function update_views_using_cache($post_id, $force = false)
{
$times = wp_cache_get($post_id, __CLASS__);
$meta = (int) get_post_meta($post_id, self::$post_meta_key, true) + (int) $times;
/**
* force to update db
*/
if ($force) {
$meta++;
wp_cache_set($post_id, 0, __CLASS__, self::$expire);
update_post_meta($post_id, self::$post_meta_key, $meta);
/**
* update cache
*/
} else {
/**
* if views more than storage times, update db and reset cache
*/
if ($times >= self::get_storage_times()) {
$meta = $meta + $times + 1;
update_post_meta($post_id, self::$post_meta_key, $meta);
wp_cache_set($post_id, 0, __CLASS__, self::$expire);
/**
* update cache
*/
} else {
if ($times === false) {
wp_cache_set($post_id, 0, __CLASS__, self::$expire);
}
wp_cache_incr($post_id, 1, __CLASS__);
$meta++;
}
}
return $meta;
}
示例8: clean_comment_cache
/**
* Removes comment ID from the comment cache.
*
* @since 2.3.0
* @package WordPress
* @subpackage Cache
*
* @param int|array $ids Comment ID or array of comment IDs to remove from cache
*/
function clean_comment_cache($ids) {
foreach ( (array) $ids as $id )
wp_cache_delete($id, 'comment');
if ( function_exists( 'wp_cache_incr' ) ) {
wp_cache_incr( 'last_changed', 1, 'comment' );
} else {
$last_changed = wp_cache_get( 'last_changed', 'comment' );
wp_cache_set( 'last_changed', $last_changed + 1, 'comment' );
}
}
示例9: test_wp_cache_incr
public function test_wp_cache_incr()
{
$key = rand_str();
$this->assertFalse(wp_cache_incr($key));
wp_cache_set($key, 0);
wp_cache_incr($key);
$this->assertEquals(1, wp_cache_get($key));
wp_cache_incr($key, 2);
$this->assertEquals(3, wp_cache_get($key));
}
示例10: incr
/**
* Increment a value in the object cache.
*
* Errors if the value can't be incremented.
*
* ## OPTIONS
*
* <key>
* : Cache key.
*
* [<offset>]
* : The amount by which to increment the item's value. Default is 1.
*
* [<group>]
* : Method for grouping data within the cache which allows the same key to be used across groups.
*
* ## EXAMPLES
*
* # Increase cache value.
* $ wp cache incr my_key 2 my_group
* 50
*/
public function incr($args, $assoc_args)
{
$key = $args[0];
$offset = \WP_CLI\Utils\get_flag_value($args, 1, 1);
$group = \WP_CLI\Utils\get_flag_value($args, 2, '');
$value = wp_cache_incr($key, $offset, $group);
if (false === $value) {
WP_CLI::error('The value was not incremented.');
}
WP_CLI::print_value($value, $assoc_args);
}
示例11: count_visit
/**
* Count visit function.
*
* @global object $wpdb
* @param int $id
* @return bool
*/
private function count_visit($id)
{
global $wpdb;
$cache_key_names = array();
$using_object_cache = $this->using_object_cache();
// get day, week, month and year
$date = explode('-', date('W-d-m-Y', current_time('timestamp')));
foreach (array(0 => $date[3] . $date[2] . $date[1], 1 => $date[3] . $date[0], 2 => $date[3] . $date[2], 3 => $date[3], 4 => 'total') as $type => $period) {
if ($using_object_cache) {
$cache_key = $id . self::CACHE_KEY_SEPARATOR . $type . self::CACHE_KEY_SEPARATOR . $period;
wp_cache_add($cache_key, 0, self::GROUP);
wp_cache_incr($cache_key, 1, self::GROUP);
$cache_key_names[] = $cache_key;
} else {
// hit the db directly
// @TODO: investigate queueing these queries on the 'shutdown' hook instead instead of running them instantly?
$this->db_insert($id, $type, $period, 1);
}
}
// update the list of cache keys to be flushed
if ($using_object_cache && !empty($cache_key_names)) {
$this->update_cached_keys_list_if_needed($cache_key_names);
}
do_action('pvc_after_count_visit', $id);
return true;
}
示例12: count_tax_visit
private function count_tax_visit($id)
{
global $wpdb;
// get post id
$id = (int) (empty($id) ? get_the_ID() : $id);
if (empty($id)) {
return;
}
$ips = Post_Views_Counter()->options['general']['exclude_ips'];
// whether to count this ip
if (!empty($ips) && filter_var(preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), FILTER_VALIDATE_IP) && in_array($_SERVER['REMOTE_ADDR'], $ips, true)) {
return;
}
// get groups to check them faster
$groups = Post_Views_Counter()->options['general']['exclude']['groups'];
// whether to count this user
if (is_user_logged_in()) {
// exclude logged in users?
if (in_array('users', $groups, true)) {
return;
} elseif (in_array('roles', $groups, true) && $this->is_user_role_excluded(Post_Views_Counter()->options['general']['exclude']['roles'])) {
return;
}
} elseif (in_array('guests', $groups, true)) {
return;
}
// whether to count robots
if ($this->is_robot()) {
return;
}
// cookie already existed?
if ($this->cookie['exists']) {
// post already viewed but not expired?
if (in_array($id, array_keys($this->cookie['visited_posts']), true) && current_time('timestamp', true) < $this->cookie['visited_posts'][$id]) {
// update cookie but do not count visit
$this->save_cookie($id, $this->cookie, false);
return;
} else {
// update cookie
$this->save_cookie($id, $this->cookie);
}
} else {
// set new cookie
$this->save_cookie($id);
}
// count visit
//$this->count_visit( $id );
$cache_key_names = array();
$using_object_cache = $this->using_object_cache();
// get day, week, month and year
$date = explode('-', date('W-d-m-Y', current_time('timestamp')));
foreach (array(0 => $date[3] . $date[2] . $date[1], 1 => $date[3] . $date[0], 2 => $date[3] . $date[2], 3 => $date[3], 4 => 'total') as $type => $period) {
if ($using_object_cache) {
$cache_key = $id . self::CACHE_KEY_SEPARATOR . $type . self::CACHE_KEY_SEPARATOR . $period;
wp_cache_add($cache_key, 0, self::GROUP);
wp_cache_incr($cache_key, 1, self::GROUP);
$cache_key_names[] = $cache_key;
} else {
// hit the db directly
// @TODO: investigate queueing these queries on the 'shutdown' hook instead instead of running them instantly?
$this->db_insert_tax($id, $type, $period, 1);
}
}
// update the list of cache keys to be flushed
if ($using_object_cache && !empty($cache_key_names)) {
$this->update_cached_keys_list_if_needed($cache_key_names);
}
do_action('pvc_after_count_visit', $id);
return true;
}
示例13: invalidate_cache
/**
* Increment the cache key to gracefully invalidate Shopp specific caches
*
* @author Clifton Griffin
* @since 1.4
*
* @return void
*/
public static function invalidate_cache()
{
wp_cache_incr('shopp_cache_key');
do_action('shopp_invalidate_cache');
}
示例14: cleanup_sessions
/**
* Cleanup sessions
*/
public function cleanup_sessions()
{
global $wpdb;
if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
// Delete expired sessions
$wpdb->query($wpdb->prepare("DELETE FROM {$this->_table} WHERE session_expiry < %d", time()));
// Invalidate cache
wp_cache_incr('wc_session_prefix', 1, WC_SESSION_CACHE_GROUP);
}
}
示例15: flush
/**
* Flush cache by incrementing current cache itteration
*/
public static function flush()
{
wp_cache_incr(self::ITTR_KEY);
}