def cache(self, resource):
if not isinstance(resource, APIResource):<EOL><INDENT>raise TypeError('<STR_LIT>'.format(resource))<EOL><DEDENT>if self.__cache_max_size == <NUM_LIT:0>:<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>cache_internal_key = resource.get_cache_internal_key()<EOL>cache_index_keys = resource.get_cache_index_keys().items()<EOL><DEDENT>except NotImplementedError:<EOL><INDENT>logger.warning(<EOL>'<STR_LIT>'.format(resource)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>resource_type = type(resource)<EOL>for key, value in cache_index_keys:<EOL><INDENT>self.__cache_index_key_map[(resource_type, key, value)] = cache_internal_key<EOL><DEDENT>self.__caches[resource_type][cache_internal_key] = resource<EOL>logger.debug('<STR_LIT>'.format(resource))<EOL><DEDENT>
Insert a resource instance into appropriate resource cache