views:

248

answers:

2

How does apache handle caching of certain files, and is it possible to explicitly say that certain files should be aggressively cached more than others, through the standard config files for a given host or virtualhost?

To put it in context, I keep a lot of site content in various XML files, and I'd like to be able to say that this file will be used a lot, and therefore cache it as much as possible..? Does apache do this kind of thing intelligently and on the fly..? Will it observe which files are more popular than others and try to match cache hits appropriately..?

Lots of questions in one, but the basic idea should be clear enough.

edit: to be clear, these are resource files which are loaded and interpreted by PHP - but php as a process is spawned inside apache.. right? Please help!

+1  A: 

If you are serving the XML files directly from Apache, with no intervening CGI scripts or language module such as PHP, then you should look at mod_file_cache. From your description, I think it's what you're looking for.

zombat
Its interesting, but the XML is all parsed through php, so I'm not sure if this in particular is the solution.
danp
+2  A: 
  1. Apache is just a web-server. It doesn't know specific of your application, so it is responsibility of your application to cache results.
  2. You can use application unaware module in apache - mod_cache. Also, see example of configuration in article Caching Dynamic Content with Apache httpd. This module allows you to specify what should be cached and what shouldn't be cached.
  3. Also, you can use some PHP-specific caching mechanism, e.g. Alternative PHP Cache or memcached.
uthark
When PHP inside Apache, for example, requests a resource to be used (say a script, xml or whatever), the request is handled and originates from Apache, right? So if you are configuring Apache to use a caching extension, this also applies to any PHP resource requests..?
danp
Apache just passes request from user to your PHP script and returns back to user generated content. Apache is not aware of your domain area, business rules, etc. If you generate content that can be cached (like this question on stackoverflow - it is almost always ok if next request will not receive up to date information) then you can configure apache to cache that specific url which generated cacheable content.If your generated content should be secured and/or involves confidential information (e.g. account information page in the payment systems) then it is wrong to cache it.
uthark
Answered my question, thanks :)
danp