Add more tests for key caching, change generate template behavior