Search code examples
phpapc

apc cache compression


I want to store some key value. I see memcache api supports on-the-fly compression: memcache_set( obj, var, value, MEMCACHE_COMPRESSED, ttl )

What about apc ? I cannot find any doc.

My goal, for example in php :

function cache( $key, $value )
{
$data       = serialize( $value );  
if ( strlen( $data ) >= 1024 )  
    $data   = 'z' . gzcompress( $data, 1 );  
else  
    $data   = '=' . $data;  
return  apc_store( $key, $data, $ttl );  
}

Solution

  • APC does not support compression at the moment.

    It will probably never because its not what apc is designed to do.

    APC is more an opcode caching system than a key value memory database like memcached, altough it can be greatly used for both purposes.

    But if just storing data is your goal memcached is probably a better option because thats it purpose and the direction it will be optimized and developed in. It also supports distribution / scaling / replication / you can run it over network etc.

    However to give you an alternative. Why dont you just compress and decompress directly in your application right before/after storing/fetching from apc? You can easily define your own caching handler for that. kind of how you did it in your question already. I don't see why apc should do this "on the fly". I would personally prefer to do it in the application for more flexibility and scalability (for example you can scale it to distributet fcgi servers)