def cached_call_controller(controller, remainder, params): req = request._current_obj() if self.key: key_dict = req.args_params if self.key != NoDefault: if isinstance(self.key, (list, tuple)): key_dict = dict((k, key_dict[k]) for k in key_dict) else: key_dict = {self.key: key_dict[self.key]} else: key_dict = {} namespace, cache_key = create_cache_key( func, key_dict, req.controller_state.controller) req._fast_setattr('caching', Bunch(namespace=namespace, key=cache_key)) return _cached_call(next_caller, (controller, remainder, params), {}, namespace, cache_key, expire=self.expire, type=self.type, starttime=starttime, cache_headers=self.cache_headers, cache_response=self.cache_response, cache_extra_args=self.beaker_options)
def test_cache_key_function(self): def method(self, arg): return arg namespace, key = create_cache_key(method) assert namespace == 'tests.test_caching' assert key == 'method'
def test_cache_key_instance_method(self): class Something(object): def method(self, arg): return arg o = Something() namespace, key = create_cache_key(o.method) assert namespace == 'tests.test_caching.Something' assert key == 'method'