|
| 1 | +.. index:: |
| 2 | + single: Cache Pool |
| 3 | + single: APC Cache, APCu Cache |
| 4 | + |
| 5 | +.. _apcu-adapter: |
| 6 | + |
| 7 | +APCu Cache Adapter |
| 8 | +================== |
| 9 | + |
| 10 | +This adapter is a high-performance, shared memory cache. It can increase the |
| 11 | +application performance very significantly because the cache contents are |
| 12 | +stored in the shared memory of your server, a component that is much faster than |
| 13 | +others, such as the filesystem. |
| 14 | + |
| 15 | +.. caution:: |
| 16 | + |
| 17 | + **Requirement:** The `APCu extension`_ must be installed and active to use |
| 18 | + this adapter. |
| 19 | + |
| 20 | +This adapter can be provided an optional namespace string as its first parameter, a |
| 21 | +default cache lifetime as its second parameter, and a version string as its third |
| 22 | +parameter:: |
| 23 | + |
| 24 | + use Symfony\Component\Cache\Adapter\ApcuAdapter; |
| 25 | + |
| 26 | + $cache = new ApcuAdapter( |
| 27 | + |
| 28 | + // a string prefixed to the keys of the items stored in this cache |
| 29 | + $namespace = '', |
| 30 | + |
| 31 | + // the default lifetime (in seconds) for cache items that do not define their |
| 32 | + // own lifetime, with a value 0 causing items to be stored indefinitely (i.e. |
| 33 | + // until the APCu memory is cleared) |
| 34 | + $defaultLifetime = 0, |
| 35 | + |
| 36 | + // when set, all keys prefixed by $namespace can be invalidated by changing |
| 37 | + // this $version string |
| 38 | + $version = null |
| 39 | + ); |
| 40 | + |
| 41 | +.. caution:: |
| 42 | + |
| 43 | + It is *not* recommended to use this adapter when performing a large number of |
| 44 | + write and delete operations, as these operations result in fragmentation of the |
| 45 | + APCu memory, resulting in *significantly* degraded performance. |
| 46 | + |
| 47 | +.. tip:: |
| 48 | + |
| 49 | + Note that this adapter's CRUD operations are specific to the PHP SAPI it is running |
| 50 | + under. This means adding a cache item using the CLI will not result in the item |
| 51 | + appearing under FPM. Likewise, deletion of an item using CGI will not result in the |
| 52 | + item being deleted under the CLI. |
| 53 | + |
| 54 | +.. _`APCu extension`: https://pecl.php.net/package/APCu |
0 commit comments