Caching result of a method in Python