Added caching

Port of symfony-cmf/RoutingAutoBundle#78
Do not assign in an `if` statement