|
8 | 8 | Cache a Class Loader |
9 | 9 | ==================== |
10 | 10 |
|
11 | | -Finding the file for a particular class can be an expensive task. Luckily, |
12 | | -the ClassLoader component comes with two classes to cache the mapping |
13 | | -from a class to its containing file. Both the :class:`Symfony\\Component\\ClassLoader\\ApcClassLoader` |
14 | | -and the :class:`Symfony\\Component\\ClassLoader\\XcacheClassLoader` wrap |
15 | | -around an object which implements a ``findFile()`` method to find the file |
16 | | -for a class. |
17 | | - |
18 | | -.. note:: |
19 | | - |
20 | | - Both the ``ApcClassLoader`` and the ``XcacheClassLoader`` can be used |
21 | | - to cache Composer's `autoloader`_. |
22 | | - |
23 | | -ApcClassLoader |
24 | | --------------- |
25 | | - |
26 | | -``ApcClassLoader`` wraps an existing class loader and caches calls to its |
27 | | -``findFile()`` method using `APC`_:: |
28 | | - |
29 | | - require_once '/path/to/src/Symfony/Component/ClassLoader/ApcClassLoader.php'; |
30 | | - |
31 | | - // instance of a class that implements a findFile() method, like the ClassLoader |
32 | | - $loader = ...; |
33 | | - |
34 | | - // sha1(__FILE__) generates an APC namespace prefix |
35 | | - $cachedLoader = new ApcClassLoader(sha1(__FILE__), $loader); |
36 | | - |
37 | | - // register the cached class loader |
38 | | - $cachedLoader->register(); |
39 | | - |
40 | | - // deactivate the original, non-cached loader if it was registered previously |
41 | | - $loader->unregister(); |
42 | | - |
43 | | -XcacheClassLoader |
44 | | ------------------ |
45 | | - |
46 | | -``XcacheClassLoader`` uses `XCache`_ to cache a class loader. Registering |
47 | | -it is straightforward:: |
48 | | - |
49 | | - require_once '/path/to/src/Symfony/Component/ClassLoader/XcacheClassLoader.php'; |
50 | | - |
51 | | - // instance of a class that implements a findFile() method, like the ClassLoader |
52 | | - $loader = ...; |
53 | | - |
54 | | - // sha1(__FILE__) generates an XCache namespace prefix |
55 | | - $cachedLoader = new XcacheClassLoader(sha1(__FILE__), $loader); |
56 | | - |
57 | | - // register the cached class loader |
58 | | - $cachedLoader->register(); |
59 | | - |
60 | | - // deactivate the original, non-cached loader if it was registered previously |
61 | | - $loader->unregister(); |
62 | | - |
63 | | -.. _APC: http://php.net/manual/en/book.apc.php |
64 | | -.. _autoloader: https://getcomposer.org/doc/01-basic-usage.md#autoloading |
65 | | -.. _XCache: http://xcache.lighttpd.net |
| 11 | +The ``ApcClassLoader``, the ``WinCacheClassLoader`` and the ``XcacheClassLoader`` |
| 12 | +are deprecated since Symfony 3.3. Use the ``--apcu-autoloader`` option instead |
| 13 | +when dumping the autoloader using the ``composer dump-autoload`` command. |
0 commit comments