It all depends on how you want to do the caching.
HTTP caching really only makes sense when in the web context and when the particular output of the action where you're parsing and adding these files to an array is relatively static. If both of those conditions are met, then that is the best way to go.
You can easily use APC to do your caching. It makes caching the contents of a variable quite simple. Doctrine provides a cache abstraction around APC, or you can use native PHP functions.
in config.yml
services:
cache:
class: Doctrine\Common\Cache\ApcCache
then in your controller or service:
if ($yamlArray = $this->get('cache')->fetch('foo')) {
$yamlArray = unserialize($yamlArray);
} else {
// do the work
$this->get('cache')->save('foo', serialize($yamlArray));
}
- Make your own caching service and hook it into the Symfony cache commands
Details on creating a cache warmer
Details on cache_clearer(added but not well documented).