def check_cache(resource_type):
    """Decorator for adapter methods to check cache for resource before normally sending requests to retrieve data

    Only works with single kwargs, almost always used with @one_of_keyword_only decorator

    Args:
        resource_type (type(APIResource)): Subclass of APIResource of cache to be checked when called
    """

    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            try:
                adapter = args[0]
                key, val = list(kwargs.items())[0]
            except IndexError:
                logger.warning("Couldn't generate full index key, skipping cache")
            else:

                index_key = (resource_type, key, val)
                try:
                    cached_record = adapter._swimlane.resources_cache[index_key]
                except KeyError:
                    logger.debug('Cache miss: `{!r}`'.format(index_key))
                else:
                    logger.debug('Cache hit: `{!r}`'.format(cached_record))
                    return cached_record

            # Fallback to default function call
            return func(*args, **kwargs)

        return wrapper
    return decorator
def check_cache ( resource_type ) : def decorator ( func ) : @ functools . wraps ( func ) def wrapper ( * args , ** kwargs ) : try : adapter = args [ 0 ] key , val = list ( kwargs . items ( ) ) [ 0 ] except IndexError : logger . warning ( "Couldn't generate full index key, skipping cache" ) else : index_key = ( resource_type , key , val ) try : cached_record = adapter . _swimlane . resources_cache [ index_key ] except KeyError : logger . debug ( 'Cache miss: `{!r}`' . format ( index_key ) ) else : logger . debug ( 'Cache hit: `{!r}`' . format ( cached_record ) ) return cached_record return func ( * args , ** kwargs ) return wrapper return decorator
Decorator for adapter methods to check cache for resource before normally sending requests to retrieve data

    Only works with single kwargs, almost always used with @one_of_keyword_only decorator

    Args:
        resource_type (type(APIResource)): Subclass of APIResource of cache to be checked when called