• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • APCIterator::__construct()

    (PECL apc >= 3.1.1)

    构造一个 APCIterator 迭代器对象

    说明

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

    构造一个APCIteratorobject.

    参数

    $cache

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

    $search

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

    $format

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

    $chunk_size

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

    $list

    需要列出的类型。可以是APC_LIST_ACTIVEAPC_LIST_DELETED

    返回值

    成功时返回APCIteratorobject,失败时返回NULL

    范例

    Example #1 APCIterator::__construct()例子

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

    参见

    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.
    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.