文字

APCIterator::__construct

(PECL apc >= 3.1.1)

APCIterator::__construct构造一个 APCIterator 迭代器对象

说明

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

构造一个 APCIterator object .

参数

cache

缓存类型,可以是 user 或者 file

search

匹配 APC 键名的 PCRE 正则表达式,既可以是单个正则表达式 string ,也可以是 array 的正则表达式。或者可以是 NULL 来略过搜索。

format

需要的格式可以用一个或多个 APC_ITER_* 常量。

chunk_size

块的大小。必须是一个大于0的值,默认是100。

list

需要列出的类型。可以是 APC_LIST_ACTIVE APC_LIST_DELETED

返回值

成功时返回 APCIterator object ,失败时返回 NULL

范例

Example #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() - 检查APC中是否存在某个或者某些key
  • apc_cache_info() - Retrieves cached information from APC's data store

用户评论:

[#1] puiumarius at gmail dot com [2014-04-18 09:13:21]

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.

[#2] petabyte [2011-08-10 06:38:15]

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).')');
?>

[#3] Anti Veeranna [2010-10-27 12:46:49]

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.

上一篇: 下一篇: