Fixed #23441: Maximum recursion depth exceeded in templates

When using custom `inclusion_tag` with recursion in templates
and `django.template.loaders.cached.Loader` for template loader.