コード例 #1
0
    def __call__(self, state: Cached, inputs: Dict[str, Any], parameters: Dict[str, Any]):
        # Never use cache when force is set
        if self.force:
            logger.debug('Cache miss: forced is set')
            return False

        # When caching with inputs and outputs, defer to the corresponding
        # prefect cache validators
        if self.use_inputs and self.use_parameters:
            input_cache = all_inputs(state, inputs, parameters)
            param_cache = all_parameters(state, inputs, parameters)
            result = input_cache and param_cache
            logger.debug('Cache %s: inputs was %s, params was %s',
                         'hit' if result else 'miss',
                         input_cache, param_cache)

        elif self.use_inputs:
            input_cache = all_inputs(state, inputs, parameters)
            result = input_cache
            logger.debug('Cache %s: inputs was %s',
                         'hit' if result else 'miss',
                         input_cache)
            return input_cache

        elif self.use_parameters:
            param_cache = all_parameters(state, inputs, parameters)
            result = param_cache
            logger.debug('Cache %s: parameters was %s',
                         'hit' if result else 'miss',
                         param_cache)
            return param_cache
        else:
            result = False
            logger.debug('Cache miss: no cache configuration set')

        if result:
            logger.info('Cache hit!')

        return result
コード例 #2
0
 def test_additional_inputs_invalidate(self):
     state = Cached(cached_inputs=dict(x=1, s="str"))
     assert all_inputs(state, dict(x=1, s="str", noise="e"), None) is False
コード例 #3
0
 def test_hashed_inputs_validate(self):
     state = Cached(hashed_inputs=dict(x=tokenize(1), s=tokenize("str")))
     assert all_inputs(state, dict(x=1, s="str"), None) is True
コード例 #4
0
 def test_inputs_validate(self):
     state = Cached(cached_inputs=dict(x=1, s="str"))
     assert all_inputs(state, dict(x=1, s="str"), None) is True
コード例 #5
0
 def test_inputs_invalidate(self):
     state = Cached(cached_inputs=dict(x=Result(1), s=Result("str")))
     assert all_inputs(state, dict(x=1, s="strs"), None) is False