WP_Object_Cache::add() public WP 2.0.0
Adds data to the cache if it doesn't already exist.
{} Это метод класса: WP_Object_Cache{}
Хуков нет.
Возвращает
true/false. True on success, false if cache key and group already exist.
Использование
$WP_Object_Cache = new WP_Object_Cache(); $WP_Object_Cache->add( $key, $data, $group, $expire );
- $key(число/строка) (обязательный)
- What to call the contents in the cache.
- $data(разное) (обязательный)
- The contents to store in the cache.
- $group(строка)
- Where to group the cache contents.
По умолчанию: 'default' - $expire(число)
- When to expire the cache contents.
По умолчанию: 0 (no expiration)
Список изменений
С версии 2.0.0 | Введена. |
Код WP_Object_Cache::add() WP Object Cache::add WP 5.6.2
public function add( $key, $data, $group = 'default', $expire = 0 ) {
if ( wp_suspend_cache_addition() ) {
return false;
}
if ( empty( $group ) ) {
$group = 'default';
}
$id = $key;
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
$id = $this->blog_prefix . $key;
}
if ( $this->_exists( $id, $group ) ) {
return false;
}
return $this->set( $key, $data, $group, (int) $expire );
}