Search code examples
phpcachingapc

APC User Cache Key collisions on multiple sites


What's the best option for avoiding key collisions between multiple sites running on the same server using APC for user caching?

I've run into issues where 2 or more sites were using the same cache key and expecting different types of items to be stored under it--one expecting a json string, the other an array, another an object.

Is their a way to segment APC by site?

BTW: I'm using APC with Apache running prefork and mod_php.


Solution

  • Perhaps you could append the server hostname to the key, you could define a constant or create some model for handling your APC:

    <?php 
    define('APC_HOST_KEY',$_SERVER['HTTP_HOST']);
    
    apc_store(APC_HOST_KEY.'_value_key', $value);
    ?>