How to Clear Caches With the PHP Function apcu_clear_cache
PHP’s APCu library can improve performance by caching data and reducing database calls. But it’s important to clear caches as often as possible to avoid a buildup of old information. In this article, Reintech’s PHP developer, Jeremy Clark, explains how to do it by using the built-in function apcu_clear_cache.
APCu is the official replacement for the outdated APC extension. APC provided both opcode caching (opcache) and object caching functionality. Since PHP 5.5 and later include their own opcache, APCu now only provides object caching functionality, which is what Drupal uses.
The apcu_clear_cache function clears the APCu data cache for a single application container. This includes both the user and system caches. APCu’s user cache stores a key/value pair, and the system cache, which holds the opcode cache, is per-process rather than shared memory.
If you’re unable to clear your cache using this method, you may need to change the shm_size in your service configuration. Otherwise, you’ll need to run a script or use the Clear Caches button in your Site Dashboard to clean your cache. If this doesn’t work, you may need to restart your server. Alternatively, you can use a third-party tool like CacheTool to connect to a FastCGI daemon (such as PHP-FPM) and operate on its cache.