''

def save(self, body, layer, coord, format):

    sys.stderr.write(('save    %d/%d/%d,    %s' % (coord.zoom, coord.column, coord.row, format)))
    path = self._filepath(layer, coord, format)
    size = self._write(body, path, format)
    db = connect(self.dbpath).cursor()
    try:
        db.execute('INSERT    INTO    tiles\n                                                                                                        (size,    used,    path)\n                                                                                                        VALUES    (?,    ?,    ?)', (size, int(time.time()), path))
    except IntegrityError:
        db.execute('UPDATE    tiles\n                                                                                                        SET    size=?,    used=?\n                                                                                                        WHERE    path=?', (size, int(time.time()), path))
    row = db.execute('SELECT    SUM(size)    FROM    tiles').fetchone()
    if (row and (row[0] > self.limit)):
        over = (row[0] - self.limit)
        while (over > 0):
            row = db.execute('SELECT    path,    size    FROM    tiles    ORDER    BY    used    ASC    LIMIT    1').fetchone()
            if (row is None):
                break
            (path, size) = row
            db.execute('DELETE    FROM    tiles    WHERE    path=?', (path,))
            self._remove(path)
            over -= size
            sys.stderr.write(('delete    ' + path))
    db.connection.commit()
    db.connection.close()
