How to clear user cache in APCu?

Keloglan picture Keloglan · Aug 29, 2014 · Viewed 9.4k times · Source

I have tried to clear the user cache using this PHP code and access it from the browser:

<?php

apc_clear_cache();
apc_clear_cache('user');
apc_clear_cache('opcode');

echo json_encode(array(
    'success' => true,
));

but it doesn't work. (I am using these tools to see if it's working or not https://rtcamp.com/tutorials/php/zend-opcache/ )

Also when the user cache gets full, it doesn't restart from 0. The APCu just stops working.

I have tried to set apc.user_ttl=0, but APCu doesn't recognize it.

My settings are:

extension=apcu.so
apc.enabled=1
apc.shm_size=10240M
apc.ttl=7200
apc.enable_cli=1
apc.gc_ttl=3600
apc.entries_hint=4096
apc.slam_defense=0
apc.enable_cli = 1
apc.user_ttl=0
apc.serializer=igbinary

Answer

Aistis picture Aistis · Mar 30, 2016
<?php

if (extension_loaded('apc')) {
    echo "APC-User cache: " . apc_clear_cache('user') . "\n";
    echo "APC-System cache: " . apc_clear_cache() . "\n";
}

if (extension_loaded('apcu')) {
    echo "APCu cache: " . apcu_clear_cache() . "\n";
}

if (function_exists('opcache_reset')) {
    // Clear it twice to avoid some internal issues...
    opcache_reset();
    opcache_reset();
}