Caching get_matching_ad_code return value

get_matching_ad_code() might be expensive when there's a lot of ad codes with complex conditionals. Mitigate that by caching matched ad code results.