<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cache_generator(self, key, generator):
 """Cache result of generator into dictionary Used to cache inference results"""

        results = []
        for result in generator:
            results.append(result)
            yield result

        self.inferred[key] = tuple(results)