Improve performance of tag handling with some caching