More resilient template directory handling for bytecode cache.