PHP教程

PHP APCu用户缓存

APCu是PHP版本的内存键值存储,其中的键是字符串类型,而值可以是PHP中的任何变量。APCu仅支持用户空间(userland)级别的变量缓存,这意味着它只能在PHP应用程序的用户代码中使用,而无法用于系统级别的缓存。

APCu 缓存在 Windows 上是按进程的,所以当使用基于进程(而不是基于线程)的 SAPI 时,它不会在不同的进程之间共享。APCu 是去除了操作码缓存的 APC,第一个 APCu 代码库版本是 v4.0.0,是在那时从 APC master 分支中 fork 出来的, APCu v5.0.0 起提供 PHP 7 支持,自 APCu v5.1.19 起提供 PHP 8 支持。

一、预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

  • APC_ITER_ALL (int)
  • APC_ITER_ATIME (int)
  • APC_ITER_CTIME (int)
  • APC_ITER_DEVICE (int)
  • APC_ITER_DTIME (int)
  • APC_ITER_FILENAME (int)
  • APC_ITER_INODE (int)
  • APC_ITER_KEY (int)
  • APC_ITER_MD5 (int)
  • APC_ITER_MEM_SIZE (int)
  • APC_ITER_MTIME (int)
  • APC_ITER_NONE (int)
  • APC_ITER_NUM_HITS (int)
  • APC_ITER_REFCOUNT (int)
  • APC_ITER_TTL (int)
  • APC_ITER_TYPE (int)
  • APC_ITER_VALUE (int)
  • APC_LIST_ACTIVE (int)
  • APC_LIST_DELETED (int)

二、APCu函数

  • apcu_add — 缓存一个新变量到存储中;
  • apcu_cache_info — 从 APCu 存储中获取缓存信息;
  • apcu_cas — Updates an old value with a new value;
  • apcu_clear_cache — Clears the APCu cache;
  • apcu_dec — Decrease a stored number;
  • apcu_delete — Removes a stored variable from the cache;
  • apcu_enabled — Whether APCu is usable in the current environment;
  • apcu_entry — Atomically fetch or generate a cache entry;
  • apcu_exists — Checks if entry exists;
  • apcu_fetch — Fetch a stored variable from the cache;
  • apcu_inc — Increase a stored number;
  • apcu_key_info — Get detailed information about the cache key;
  • apcu_sma_info — Retrieves APCu Shared Memory Allocation information;
  • apcu_store — 缓存一个变量到存储中。

三、APCUIterator类

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

类摘要:

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

温馨提示:

1、本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。邮箱:2942802716#qq.com。(#改为@)

2、本站原创内容未经允许不得转裁,转载请注明出处“站长百科”和原文地址。

目录