APCIterator::__construct
(PECL apc >= 3.1.1)
APCIterator::__construct — Constructs an APCIterator iterator object
Описание
$cache
[, mixed $search
= null
[, int $format
= APC_ITER_ALL
[, int $chunk_size
= 100
[, int $list
= APC_LIST_ACTIVE
]]]] )Constructs an APCIterator object.
Список параметров
-
cache
-
The cache type, which will be user or file.
-
search
-
A PCRE regular expression that matches against APC key names, either as a string for a single regular expression, or as an array of regular expressions. Or, optionally pass in
NULL
to skip the search. -
format
-
The desired format, as configured with one or more of the APC_ITER_* constants.
-
chunk_size
-
The chunk size. Must be a value greater than 0. The default value is 100.
-
list
-
The type to list. Either pass in
APC_LIST_ACTIVE
orAPC_LIST_DELETED
.
Возвращаемые значения
An APCIterator object on success,
or NULL
on failure.
Примеры
Пример #1 A APCIterator::__construct() example
<?php
foreach (new APCIterator('user', '/^counter\./') as $counter) {
echo "$counter[key]: $counter[value]\n";
apc_dec($counter['key'], $counter['value']);
}
?>
Смотрите также
- apc_exists() - Checks if APC key exists
- apc_cache_info() - Retrieves cached information from APC's data store
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Изменение поведения PHP
- Alternative PHP Cache
- Функция APCIterator::__construct() - Constructs an APCIterator iterator object
- Функция APCIterator::current() - Get current item
- Функция APCIterator::getTotalCount() - Get total count
- Функция APCIterator::getTotalHits() - Get total cache hits
- Функция APCIterator::getTotalSize() - Get total cache size
- Функция APCIterator::key() - Get iterator key
- Функция APCIterator::next() - Move pointer to next item
- Функция APCIterator::rewind() - Rewinds iterator
- Функция APCIterator::valid() - Checks if current position is valid
Коментарии
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.
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).')');
?>
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.