Clear association cache recursively before cache write
Move clear_association_cache out of loop