コード例 #1
0
    def _get_from_cache(self, target_self, *args, **kwargs):
        target_self_cls_name = reflection.get_class_name(target_self,
                                                         fully_qualified=False)
        func_name = "%(module)s.%(class)s.%(func_name)s" % {
            'module': target_self.__module__,
            'class': target_self_cls_name,
            'func_name': self.func.__name__,
        }
        key = (func_name, ) + args
        if kwargs:
            key += utils.dict2tuple(kwargs)
        # oslo.cache expects a string or a buffer
        key = str(key)
        try:
            item = target_self._cache.get(key)
        except TypeError:
            LOG.debug(
                "Method %(func_name)s cannot be cached due to "
                "unhashable parameters: args: %(args)s, kwargs: "
                "%(kwargs)s", {
                    'func_name': func_name,
                    'args': args,
                    'kwargs': kwargs
                })
            return self.func(target_self, *args, **kwargs)

        if item is self._not_cached:
            item = self.func(target_self, *args, **kwargs)
            target_self._cache.set(key, item)

        return item
コード例 #2
0
ファイル: cache_utils.py プロジェクト: annp/neutron
    def _get_from_cache(self, target_self, *args, **kwargs):
        target_self_cls_name = reflection.get_class_name(target_self,
                                                         fully_qualified=False)
        func_name = "%(module)s.%(class)s.%(func_name)s" % {
            'module': target_self.__module__,
            'class': target_self_cls_name,
            'func_name': self.func.__name__,
        }
        key = (func_name,) + args
        if kwargs:
            key += utils.dict2tuple(kwargs)
        # oslo.cache expects a string or a buffer
        key = str(key)
        try:
            item = target_self._cache.get(key)
        except TypeError:
            LOG.debug("Method %(func_name)s cannot be cached due to "
                      "unhashable parameters: args: %(args)s, kwargs: "
                      "%(kwargs)s",
                      {'func_name': func_name,
                       'args': args,
                       'kwargs': kwargs})
            return self.func(target_self, *args, **kwargs)

        if item is self._not_cached:
            item = self.func(target_self, *args, **kwargs)
            target_self._cache.set(key, item)

        return item
コード例 #3
0
ファイル: test_utils.py プロジェクト: cisco-openstack/neutron
 def test_dict(self):
     input_dict = {'foo': 'bar', 42: 'baz', 'aaa': 'zzz'}
     expected = ((42, 'baz'), ('aaa', 'zzz'), ('foo', 'bar'))
     output_tuple = utils.dict2tuple(input_dict)
     self.assertEqual(expected, output_tuple)
コード例 #4
0
 def test_dict(self):
     input_dict = {'foo': 'bar', '42': 'baz', 'aaa': 'zzz'}
     expected = (('42', 'baz'), ('aaa', 'zzz'), ('foo', 'bar'))
     output_tuple = utils.dict2tuple(input_dict)
     self.assertEqual(expected, output_tuple)
コード例 #5
0
ファイル: test_utils.py プロジェクト: manjeetbhatia/test_l3
 def test_dict(self):
     input_dict = {"foo": "bar", "42": "baz", "aaa": "zzz"}
     expected = (("42", "baz"), ("aaa", "zzz"), ("foo", "bar"))
     output_tuple = utils.dict2tuple(input_dict)
     self.assertEqual(expected, output_tuple)