跳到内容

APCu 缓存适配器

编辑此页

此适配器是高性能的共享内存缓存。它可以显著提高应用程序的性能,因为其缓存内容存储在共享内存中,这是一种比许多其他组件(如文件系统)快得多的组件。

警告

要求: 必须安装并激活 APCu 扩展 才能使用此适配器。

ApcuAdapter 可以选择性地作为构造函数参数提供命名空间、默认缓存生命周期和缓存项版本字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use Symfony\Component\Cache\Adapter\ApcuAdapter;

$cache = new ApcuAdapter(

    // a string prefixed to the keys of the items stored in this cache
    $namespace = '',

    // the default lifetime (in seconds) for cache items that do not define their
    // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
    // until the APCu memory is cleared)
    $defaultLifetime = 0,

    // when set, all keys prefixed by $namespace can be invalidated by changing
    // this $version string
    $version = null
);

警告

不鼓励在写入/删除密集型工作负载中使用此适配器,因为这些操作会导致内存碎片,从而显著降低性能。

提示

此适配器的 CRUD 操作特定于它正在运行的 PHP SAPI。这意味着使用 CLI 的缓存操作(例如添加、删除等)在 FPM 或 CGI SAPI 下将不可用。

这项工作,包括代码示例,根据 Creative Commons BY-SA 3.0 许可获得许可。
目录
    版本