Re: [APC-DEV] Caching file_get_contents output inside APC (Performance improvement).

[email protected] (shire) Wed, 28 Oct 2009 00:56:41 -0700
Newsgroups php.pecl.dev,php.apc.dev
Message-ID <[email protected]>
Hi Basant,

Basant Kukreja wrote:

> On Mon, Oct 26, 2009 at 2:14 PM, Pierre Joye <[email protected]> wrote:
>>
>> (pseudo code where my_cache* could be either APC user cache, memcached
>> or other caching lib like Cache_Lite)
>> if (!($cached = my_cache_get($key))) {
>>   $data = file_get_contents($path);
>>   my_cache_add($data, $ttl);
>> }
>>
>
>      Probably it will perform close to the version I attached but my
> point is that application doesn't
> need to be modified and can use this feature by modifying configuration.
>
> More options which I think of which can be used to extend the caching feature :
> apc.cache_max_file_size    # Maximum amount of files to be cached
> apc.max_cache_use_bytes # Maximum amount of space to be occupied in cache.
>


Thanks for the patch/suggested feature but I tend to agree with Pierre's suggestion for handling this in user space.  This is an extremely simple wrapper function to enable caching these values, and as your additional configuration items suggest, placing this functionality in APC creates some unnecessary complications and less flexibility for the PHP developer.

The intention of the APC user cache is to allow extending it in PHP user space for caching any number of items like this, using the very method Pierre suggested.  Heading in the direction you're suggesting would mean that APC should be responsible for caching all sorts of stream and file based activities that PHP and even other extensions could perform without knowing enough about the data to do it in an intelligent way.

Unless you can provide reasons why the APC extension in particular is in a situation to handle this better than anything else, I don't see a compelling reason to start adding this type of functionality.

-shire