Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ClassLoader] deprecate caching class loaders #7258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion 10 components/class_loader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ Learn More
:maxdepth: 1

class_loader/class_loader
class_loader/*
class_loader/class_map_generator.rst
class_loader/debug_class_loader.rst
class_loader/map_class_loader.rst
class_loader/psr4_class_loader.rst

.. toctree::
:hidden:

class_loader/cache_class_loader

.. _PSR-0: http://www.php-fig.org/psr/psr-0/
.. _PSR-4: http://www.php-fig.org/psr/psr-4/
Expand Down
59 changes: 4 additions & 55 deletions 59 components/class_loader/cache_class_loader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,7 @@
Cache a Class Loader
====================

Finding the file for a particular class can be an expensive task. Luckily,
the ClassLoader component comes with two classes to cache the mapping
from a class to its containing file. Both the :class:`Symfony\\Component\\ClassLoader\\ApcClassLoader`
and the :class:`Symfony\\Component\\ClassLoader\\XcacheClassLoader` wrap
around an object which implements a ``findFile()`` method to find the file
for a class.

.. note::

Both the ``ApcClassLoader`` and the ``XcacheClassLoader`` can be used
to cache Composer's `autoloader`_.

ApcClassLoader
--------------

``ApcClassLoader`` wraps an existing class loader and caches calls to its
``findFile()`` method using `APC`_::

require_once '/path/to/src/Symfony/Component/ClassLoader/ApcClassLoader.php';

// instance of a class that implements a findFile() method, like the ClassLoader
$loader = ...;

// sha1(__FILE__) generates an APC namespace prefix
$cachedLoader = new ApcClassLoader(sha1(__FILE__), $loader);

// register the cached class loader
$cachedLoader->register();

// deactivate the original, non-cached loader if it was registered previously
$loader->unregister();

XcacheClassLoader
-----------------

``XcacheClassLoader`` uses `XCache`_ to cache a class loader. Registering
it is straightforward::

require_once '/path/to/src/Symfony/Component/ClassLoader/XcacheClassLoader.php';

// instance of a class that implements a findFile() method, like the ClassLoader
$loader = ...;

// sha1(__FILE__) generates an XCache namespace prefix
$cachedLoader = new XcacheClassLoader(sha1(__FILE__), $loader);

// register the cached class loader
$cachedLoader->register();

// deactivate the original, non-cached loader if it was registered previously
$loader->unregister();

.. _APC: http://php.net/manual/en/book.apc.php
.. _autoloader: https://getcomposer.org/doc/01-basic-usage.md#autoloading
.. _XCache: http://xcache.lighttpd.net
The ``ApcClassLoader``, the ``WinCacheClassLoader`` and the ``XcacheClassLoader``
are deprecated since Symfony 3.3. Use the ``--optimize`` and ``--apcu-autoloader``
options instead when dumping the autoloader using the ``composer dump-autoload``
command.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.