Added caching

Port of symfony-cmf/RoutingAutoBundle#78
Again my brain had trouble decoding this line. Can you break out the logic here?