PHP Velho Oeste 2024

APCIterator::__construct

(PECL apc >= 3.1.1)

APCIterator::__constructСоздать объект итератора APCIterator

Описание

public APCIterator::__construct ( string $cache [, mixed $search = NULL [, int $format = APC_ITER_ALL [, int $chunk_size = 100 [, int $list = APC_LIST_ACTIVE ]]]] )

Создаёт объект APCIterator.

Список параметров

cache

Тип кэша, который должен быть user или file.

search

PCRE регулярное выражение, которое соответствует именам ключей APC, строка для единственного регулярного выражения, или массив регулярных выражений. Или, дополнительно передайте NULL для пропуска поиска.

format

Нужный формат, как заданно одной или несколькими константами APC_ITER_*.

chunk_size

Размер блока. Должен быть больше 0. Значение по умолчанию равно 100.

list

Тип для перечисления. APC_LIST_ACTIVE или APC_LIST_DELETED.

Возвращаемые значения

Объект APCIterator в случае успеха, или NULL, в случае неудачи.

Примеры

Пример #1 Пример использования APCIterator::__construct()

<?php
foreach (new APCIterator('user''/^counter\./') as $counter) {
    echo 
"$counter[key]$counter[value]\n";
    
apc_dec($counter['key'], $counter['value']);
}
?>

Смотрите также

  • apc_exists() - Проверить, существует ли ключ APC
  • apc_cache_info() - Получить кешируемую информацию и метаданные из хранилища данных APC
add a note add a note

User Contributed Notes 3 notes

up
1
petabyte
12 years ago
With MAMP (using PHP 5.3.5 and APC 3.1.7) passing an array with multiple regex strings as $search arg always yields an empty APCIterator. Whereas passing a single string regex works. (Note: I only tried cache type 'user'.)

Workaround: Concatenated all regexes to single one with alternation. Example:

<?php
$results
= new APCIterator('user', '/^('.implode('|', $patterns).')');
?>
up
-2
puiumarius at gmail dot com
10 years ago
There is a bug in APCIterator: whatever the chunk size, APCIterator gets ALL keys matching the specified pattern (it seems that $chunk_size parameter is ignored).

Also, the documentation states that the default chunk size is 100, but even that is ignored.

Tested APC version is 3.1.13.

Example (I have 180 keys for this pattern in total):
$objIterator = new APCIterator('user', '/^key_prefix_\.*/', APC_ITER_ALL, 20);

If I itterate $objIterator  and then count() the results, I get 180.

Also, for:
$objIterator = new APCIterator('user', '/^key_prefix_\.*/');
Same count(), 180.

Even $objIterator->getTotalCount() returns 180.
up
-1
Anti Veeranna
13 years ago
Iterating (and specifically using current()) does not expunge cache entries for which $ttl has passed, you need to use apc_fetch to get rid of stale entries.
To Top