本文整理汇总了PHP中wp_cache_incr函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_incr函数的具体用法?PHP wp_cache_incr怎么用?PHP wp_cache_incr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_incr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:trishasalas,项目名称:rgy,代码行数:25,代码来源:batcache.php
示例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);
}
开发者ID:amandhare,项目名称:vip-quickstart,代码行数:10,代码来源:batcache.php
示例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');
}
开发者ID:humanmade,项目名称:vip-mu-plugins-public,代码行数:13,代码来源:security.php
示例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;
}
}
开发者ID:Automattic,项目名称:vip-mu-plugins-public,代码行数:32,代码来源:class-lock.php
示例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);
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:7,代码来源:class-wpml-wp-cache.php
示例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');
}
开发者ID:spacedmonkey,项目名称:batcache-manager,代码行数:8,代码来源:batcache-stats.php
示例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;
}
开发者ID:ClayMoreBoy,项目名称:wp-theme-inn2015v2,代码行数:43,代码来源:post-views.php
示例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' );
}
}
开发者ID:pauEscarcia,项目名称:AIMM,代码行数:20,代码来源:COMMENT.PHP
示例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));
}
开发者ID:pantheon-systems,项目名称:wp-redis,代码行数:10,代码来源:test-cache.php
示例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);
}
开发者ID:wp-cli,项目名称:wp-cli,代码行数:33,代码来源:cache.php
示例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;
}
开发者ID:alons182,项目名称:sonnsolar,代码行数:33,代码来源:counter.php
示例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;
}
开发者ID:kanhaiyasharma,项目名称:Bestswiss,代码行数:70,代码来源:counter.php
示例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');
}
开发者ID:borkweb,项目名称:shopp,代码行数:13,代码来源:Core.php
示例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);
}
}
开发者ID:randyriolis,项目名称:woocommerce,代码行数:13,代码来源:class-wc-session-handler.php
示例15: flush
/**
* Flush cache by incrementing current cache itteration
*/
public static function flush()
{
wp_cache_incr(self::ITTR_KEY);
}
开发者ID:andrejcremoznik,项目名称:wp-cache-helper,代码行数:7,代码来源:WpCacheHelper.php
示例16: clear_caches
/**
* Clear the key used for wp_cache_get and wp_cache_set
* Run this when options etc have been changed so fresh values are fetched upon next get
*/
function clear_caches()
{
do_action("simple_fields_clear_caches");
$prev_key = $this->ns_key;
$this->ns_key = wp_cache_incr('simple_fields_namespace_key', 1, 'simple_fields');
// this can consume lots of memory if we for example use set_value a lot because
// it gets all field values and such and then increase the namespace key, bloating up the memory
// kinda correct, but kinda too much memory
// this is perhaps naughty, but will work: get all keys belonging to simple fields and just remove them
global $wp_object_cache;
if (isset($wp_object_cache->cache["simple_fields"])) {
// cache exists for simple fields
// remove all keys
// This started getting error after updating to WP 4
// https://wordpress.org/support/topic/notice-indirect-modification-of-overloaded-property-wp_object_cachecache
// $wp_object_cache->cache["simple_fields"] = array();
$cache = $wp_object_cache->cache;
$cache['simple_fields'] = array();
$wp_object_cache->cache = $cache;
}
if ($this->ns_key === FALSE) {
// I really don't know why, but wp_cache_incr returns false...always or sometimes?
// Manually update namespace key by one
$this->ns_key = $prev_key + 1;
wp_cache_set('simple_fields_namespace_key', $this->ns_key, 'simple_fields');
}
// echo "clear_key";var_dump($this->ns_key);
}
开发者ID:karenwingyee,项目名称:Superdry-blog,代码行数:32,代码来源:simple_fields.php
示例17: clear_url
/**
*
* @param $url
*
* @return bool|false|int
*/
public static function clear_url($url)
{
global $batcache, $wp_object_cache;
$url = apply_filters('batcache_manager_link', $url);
if (empty($url)) {
return false;
}
do_action('batcache_manager_before_flush', $url);
// Force to http
$url = set_url_scheme($url, 'http');
$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;
}
do_action('batcache_manager_after_flush', $url, $retval);
return $retval;
}
开发者ID:spacedmonkey,项目名称:batcache-manager,代码行数:30,代码来源:batcache-manager.php
示例18: incr
/**
* Increment a value in the object cache.
*
* @synopsis <key> [<offset>] [<group>]
*/
public function incr($args, $assoc_args)
{
$key = $args[0];
$offset = isset($args[1]) ? $args[1] : 1;
$group = isset($args[2]) ? $args[2] : '';
$value = wp_cache_incr($key, $offset, $group);
if (false === $value) {
WP_CLI::error('The value was not incremented.');
exit;
}
WP_CLI::print_value($value, $assoc_args);
}
开发者ID:nb,项目名称:wp-cli,代码行数:17,代码来源:cache.php
示例19: clean_url
/**
* Clear a cached URL
*
* @since 2.3.0
*
* @param string $url
*
* @return boolean
*/
public static function clean_url($url = '')
{
// Bail if no URL
if (empty($url)) {
return false;
}
// Bail if no persistent output cache
if (!function_exists('wp_output_cache')) {
return false;
}
// Normalize the URL
if (0 === strpos($url, 'https://')) {
$url = str_replace('https://', 'http://', $url);
}
if (0 !== strpos($url, 'http://')) {
$url = 'http://' . $url;
}
$url_key = md5($url);
// Get cache objects
$output_cache = wp_output_cache_init();
$object_cache = wp_object_cache_init();
// Bail if either cache is missing
if (empty($output_cache) || empty($object_cache)) {
return;
}
wp_cache_add("{$url_key}_version", 0, $output_cache->group);
$retval = wp_cache_incr("{$url_key}_version", 1, $output_cache->group);
$output_cache_no_remote_group_key = array_search($output_cache->group, (array) $object_cache->no_remote_groups);
// The *_version key needs to be replicated remotely, otherwise invalidation won't work.
// The race condition here should be acceptable.
if (false !== $output_cache_no_remote_group_key) {
unset($object_cache->no_remote_groups[$output_cache_no_remote_group_key]);
$retval = wp_cache_set("{$url_key}_version", $retval, $output_cache->group);
$object_cache->no_remote_groups[$output_cache_no_remote_group_key] = $output_cache->group;
}
return $retval;
}
开发者ID:stuttter,项目名称:wp-spider-cache,代码行数:46,代码来源:wp-spider-cache.php
示例20: start
/**
* Start page caching and hook into requests to complete it later
*
* @since 2.1.0
*
* @return void
*/
protected function start()
{
// Bail if cookies indicate a cache-exempt visitor
if (is_array($_COOKIE) && !empty($_COOKIE)) {
$cookie_keys = array_keys($_COOKIE);
foreach ($cookie_keys as $this->cookie) {
if (!in_array($this->cookie, $this->noskip_cookies) && (substr($this->cookie, 0, 2) === 'wp' || substr($this->cookie, 0, 9) === 'wordpress' || substr($this->cookie, 0, 14) === 'comment_author')) {
return;
}
}
}
// Disabled
if ($this->max_age < 1) {
return;
}
// Necessary to prevent clients using cached version after login cookies
// set. If this is a problem, comment it out and remove all
// Last-Modified headers.
header('Vary: Cookie', false);
// Things that define a unique page.
if (isset($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $this->query);
}
// Build different versions for HTTP/1.1 and HTTP/2.0
if (isset($_SERVER['SERVER_PROTOCOL'])) {
$this->unique['server_protocol'] = $_SERVER['SERVER_PROTOCOL'];
}
// Setup keys
$this->keys = array('host' => $_SERVER['HTTP_HOST'], 'method' => $_SERVER['REQUEST_METHOD'], 'path' => ($this->pos = strpos($_SERVER['REQUEST_URI'], '?')) ? substr($_SERVER['REQUEST_URI'], 0, $this->pos) : $_SERVER['REQUEST_URI'], 'query' => $this->query, 'extra' => $this->unique, 'ssl' => $this->is_ssl());
// Recreate the permalink from the URL
$protocol = true === $this->keys['ssl'] ? 'https://' : 'http://';
$this->permalink = $protocol . $this->keys['host'] . $this->keys['path'] . (isset($this->keys['query']['p']) ? "?p=" . $this->keys['query']['p'] : '');
$this->url_key = md5($this->permalink);
$this->url_version = (int) wp_cache_get("{$this->url_key}_version", $this->group);
// Setup keys and variants
$this->do_variants();
$this->generate_keys();
// Get the spider_cache
$this->cache = wp_cache_get($this->key, $this->group);
// Are we only caching frequently-requested pages?
if ($this->seconds < 1 || $this->times < 2) {
$this->do = true;
} else {
// No spider_cache item found, or ready to sample traffic again at
// the end of the spider_cache life?
if (!is_array($this->cache) || $this->started >= $this->cache['time'] + $this->max_age - $this->seconds) {
wp_cache_add($this->req_key, 0, $this->group);
$this->requests = wp_cache_incr($this->req_key, 1, $this->group);
if ($this->requests >= $this->times) {
$this->do = true;
} else {
$this->do = false;
}
}
}
// If the document has been updated and we are the first to notice, regenerate it.
if ($this->do !== false && isset($this->cache['version']) && $this->cache['version'] < $this->url_version) {
$this->genlock = wp_cache_add("{$this->url_key}_genlock", 1, $this->group, 10);
}
// Did we find a spider_cached page that hasn't expired?
if (isset($this->cache['time']) && empty($this->genlock) && $this->started < $this->cache['time'] + $this->cache['max_age']) {
// Issue redirect if cached and enabled
if ($this->cache['redirect_status'] && $this->cache['redirect_location'] && $this->cache_redirects) {
$status = $this->cache['redirect_status'];
$location = $this->cache['redirect_location'];
// From vars.php
$is_IIS = strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false;
$this->do_headers($this->headers);
if (!empty($is_IIS)) {
header("Refresh: 0;url={$location}");
} else {
if (php_sapi_name() !== 'cgi-fcgi') {
$texts = array(300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect');
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ('HTTP/1.1' !== $protocol && 'HTTP/1.0' !== $protocol) {
$protocol = 'HTTP/1.0';
}
if (isset($texts[$status])) {
header("{$protocol} {$status} " . $texts[$status]);
} else {
header("{$protocol} 302 Found");
}
}
header("Location: {$location}");
}
exit;
}
// Respect ETags served with feeds.
$three_oh_four = false;
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && isset($this->cache['headers']['ETag'][0]) && $_SERVER['HTTP_IF_NONE_MATCH'] == $this->cache['headers']['ETag'][0]) {
$three_oh_four = true;
// Respect If-Modified-Since.
} elseif ($this->cache_control && isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
//.........这里部分代码省略.........
开发者ID:Ramoonus,项目名称:wp-spider-cache,代码行数:101,代码来源:class-output-cache.php
注:本文中的wp_cache_incr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论