Extract handling of template cache.