'Get status code, headers, and a tile binary for a given request layer tile.
Arguments:
- coord: one ModestMaps.Core.Coordinate corresponding to a single tile.
- extension: filename extension to choose response type, e.g. "png" or "jpg".
- ignore_cached: always re-render the tile, whether it\'s in the cache or not.
This is the main entry point, after site configuration has been loaded
and individual tiles need to be rendered.'

def getTileResponse(self, coord, extension, ignore_cached=False):

    start_time = time()
    (mimetype, format) = self.getTypeByExtension(extension)
    status_code = 200
    headers = Headers([('Content-Type', mimetype)])
    body = None
    cache = self.config.cache
    if (not ignore_cached):
        try:
            body = cache.read(self, coord, format)
        except TheTileLeftANote as e:
            headers = e.headers
            status_code = e.status_code
            body = e.content
            if e.emit_content_type:
                headers.setdefault('Content-Type', mimetype)
        tile_from = 'cache'
    else:
        body = _getRecentTile(self, coord, format)
        tile_from = 'recent    tiles'
    if (body is None):
        try:
            lockCoord = None
            if self.write_cache:
                lockCoord = self.metatile.firstCoord(coord)
                cache.lock(self, lockCoord, format)
            if (not ignore_cached):
                body = cache.read(self, coord, format)
                tile_from = 'cache    after    all'
            if (body is None):
                buff = BytesIO()
                try:
                    tile = self.render(coord, format)
                    save = True
                except NoTileLeftBehind as e:
                    tile = e.tile
                    save = False
                    status_code = 404
                if (not self.write_cache):
                    save = False
                if (format.lower() == 'jpeg'):
                    save_kwargs = self.jpeg_options
                elif (format.lower() == 'png'):
                    save_kwargs = self.png_options
                else:
                    save_kwargs = {}
                tile.save(buff, format, **save_kwargs)
                body = buff.getvalue()
                if save:
                    cache.save(body, self, coord, format)
                tile_from = 'layer.render()'
        except TheTileLeftANote as e:
            headers = e.headers
            status_code = e.status_code
            body = e.content
            if e.emit_content_type:
                headers.setdefault('Content-Type', mimetype)
        finally:
            if lockCoord:
                cache.unlock(self, lockCoord, format)
    _addRecentTile(self, coord, format, body)
    logging.info('TileStache.Core.Layer.getTileResponse()    %s/%d/%d/%d.%s    via    %s    in    %.3f', self.name(), coord.zoom, coord.column, coord.row, extension, tile_from, (time() - start_time))
    return (status_code, headers, body)
