Magento DevDocs recommends to use APCu. I have enabled it and it works somehow, but I don't why and, and when to do what. I use already apc.php. Can anyone share some knowledge regarding APCu and Magento usage? I just would like to get a basic grasp, although I know not all is directly related to Magento...

Some questions:

  • Is it only used by composer and its class loading? Does Magento use it directly?

  • When does the cache get populated? It seems that composer dump-autoload -o --apcu generates (just) 3 entries, loading a frontend page generates hundreds more (unfortunately not always - don't know what I'm doing wrong).

  • What happens after I've cleared the cache? E.g. with the button in apc.php. Do have I to re-populate the cache?

  • What clears the cache indirectly? E.g. a php-fpm restart? Is it a problem if the cache gets cleared?

  • If I'd like to update the autoloader, DevDocs tells to do

    composer install --no-dev
    bin/magento setup:di:compile
    composer dump-autoload -o
    bin/magento setup:static-content:deploy

    Why composer install if Magento is already installed? And what is with the parameters of composer: --optimize-autoloader and --apcu-autoloader? Why don't they get used?

  • When do I have to what regarding APCu? When do I have to pay attention? E.g. "always do ... when you do ...".

  • I observed that stored keys are prefixed with a random string. What does create that string or when does it get altered or renewed?

  • Do I have to keep anything in mind if I also use OpCache, Redis or anything else?

  • Can you recommend APCu as well? Can it be that is offers just a minimal improvement?

I appreciate any enlightenment! I hope using APCu with Magento is more easy then I think.

2 Answers 2


APCu is basically a stripped down version of APC that only includes the data caching code, and is designed to work in tandem with OpCache if you need data caching.

There is no as such implementation of APCu inside Magento's own framework or autoloading process. But we can use the implementation done by composer to improve autoloading process.

According to composer's own documentation;

This option adds an APCu cache as a fallback for the class map. It will not automatically generate the class map though, so you should still enable Level 1 optimizations manually if you so desire.

Whether a class is found or not, that fact is always cached in APCu, so it can be returned quickly on the next request.


If you want to use APCu cache in composer for an instance you have to run composer update or install whatever you are running using the --apcu-autoloader param

For this case, as you will be running composer update to upgrade to the new version you should be running

composer update --apcu-autoloader

Reference - https://getcomposer.org/doc/articles/autoloader-optimization.md#optimization-level-2-b-apcu-cache

  • Can you please explain which commands do you run after the composer update when you want to update your site and how APC autoloading gets updated? Sep 14, 2021 at 7:34
  • You have to run setup upgrade and subsequently static content deploy commands after you have upgraded any Magento instance. Regarding how APCu gets created during class map generation, it mirrors the class map however it is created when the class map is created as mentioned in my answer, it is fallback for class map. You can read up on how autoloading and class generation works here - alanstorm.com/magento_2_autoloader_and_class_generation Sep 14, 2021 at 11:25
  • I'll award the answer the reward (because then it will just be a waste), but I would like EXACT commands to run when using APCu and deploying the site after an upgrade. Sep 17, 2021 at 20:36
  • 1
    I've mentioned it in the post in the edit section. Sep 18, 2021 at 12:42
  • Is this done before compile, after compile, after upgrade, before upgrade? Sep 19, 2021 at 1:40

Here is the final order of commands that worked for me:

bin/magento setup:upgrade
composer install --no-dev
bin/magento setup:di:compile
composer dump-autoload -o --apcu
bin/magento setup:static-content:deploy
bin/magento cache:flush

After this, APC started to load up files into cache.

I don't feel any difference compared to when adding OpCache, but there were a couple of points added to Google Page speed (about 5-6 on each device type).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.