APCUIterator 类

(PECL apcu >= 5.0.0)

简介

APCUIterator 类可以更轻松的迭代大型 APCu 缓存。 它所支持的逐步迭代功能对于遍历大型缓存非常有用,每次加锁后只会获取指定数量(默认 100 条)的缓存条目就会释放锁而非一直锁住整个缓存,以便其他活动对缓存进行操作。 此外,使用正则表达式匹配是更高效的,因为它已经被移到了 C 语言层级(C level)。

类摘要

class APCUIterator implements Iterator {
/* 方法 */
public function __construct(
    array|string|null $search = null,
    int $format = APC_ITER_ALL,
    int $chunk_size = 100,
    int $list = APC_LIST_ACTIVE
)
public function current(): mixed
public function getTotalCount(): int
public function getTotalHits(): int
public function getTotalSize(): int
public function key(): string
public function next(): bool
public function rewind(): void
public function valid(): bool
}

目录

添加备注

用户贡献的备注 1 note

up
0
olliejones at gmail dot com
14 hours ago
To delete all variables from the data store with keys starting with a particular $prefix, do this.

<?php
foreach ( new APCUIterator( '/^' . preg_quote( $prefix, '/' ) . '/', APC_ITER_KEY ) as $item ) {
    apcu_delete( $item['key'] );
}
?>

It is good practice to choose a distinctive prefix for all key names. Some server configurations cause multiple domains' code to share one APCu cache, and distinctive prefixes prevent cache variable name collisions.
To Top