Did I find the right examples for you? yes no

All Samples(1)  |  Call(0)  |  Derive(0)  |  Import(1)
A convenient decorator for getting the data (either from the cache or
populating the cache).

For use on instances (not plain functions) that have a ``self._cache``
instance variable.

Usage::

    class Loader(object):
        @cachable(more...)

        def cachable(func):
    """
    A convenient decorator for getting the data (either from the cache or
    populating the cache).

    For use on instances (not plain functions) that have a ``self._cache``
    instance variable.

    Usage::

        class Loader(object):
            @cachable
            def load_service_model(self, service):
                data = self.load_file(self, 'aws/{0}'.format(service))
                return data

    """
    def _wrapper(self, orig_key, **kwargs):
        key = orig_key

        # Make the full key, including all kwargs.
        # Sort them to prevent hash randomization from creating accidental
        # cache misses.
        for name in sorted(kwargs.keys()):
            key += '/{0}/{1}'.format(
                name,
                kwargs[name]
            )

        if key in self._cache:
            return self._cache[key]

        data = func(self, orig_key, **kwargs)
        self._cache[key] = data
        return data

    return _wrapper
        


src/b/o/botocore-HEAD/tests/unit/test_loaders.py   botocore(Download)
from botocore.exceptions import ApiVersionNotFoundError
from botocore.exceptions import DataNotFoundError
from botocore.loaders import cachable
from botocore.loaders import JSONFileLoader
from botocore.loaders import Loader