Search code examples
phpgarbage-collectionapc

When does APC remove old entries?


I'm struggling to find any logic in the way APC clears up its old entries. Especially with user entries, I notice the fragmentation quickly increasing to unexpected levels.

Although apc.ttl and apc.user_ttl are set at 3600, I notice a LOT of old entries in the APC cache which are not getting cleared. I have repeatedly increased the size of the memory for APC, but it only makes it last a little longer before reaching 100% fragmentation.

So, why could this be happening? Actually I would consider this a bug in APC, it's just not normal behaviour. I would expect some APC process to clear out old entries from time to time.

Also, could it lead to the conclusion that it would be better to use another caching system for PHP, and only use APC as an opcode cache (where the lack of cleaning is less of a problem)?


Solution

  • If you want to ensure old values are removed. You need to explicitly remove it.

    I use a combination of APC and memcached in my applications. APC provides opcode caching as well as caches local data that is likely to remain unchanged (Like config files). All other objects are cached in memcached using some sort of a read through logic. (Gets cleared if data is changed)

    When I do a new release, I restart APC (via apache or php if its a separate process). That will clear the APC cache and the config files will get reloaded shortly afterwards. I will restart memcached if the objects have changed significantly enough to cause issues if its loading old cache data.