def get_cache_stats():
    """Return a dictionary containing information on the current cache stats.

    This only supports memcache.
    """
    hostnames = get_memcached_hosts()

    if not hostnames:
        return None

    all_stats = []

    for hostname in hostnames:
        try:
            host, port = hostname.split(":")
            if host == 'unix':
                socket_af = socket.AF_UNIX
                connect_param = port
            else:
                socket_af = socket.AF_INET
                connect_param = (host, int(port))

        except ValueError:
            logging.error('Invalid cache hostname "%s"' % hostname)
            continue

        s = socket.socket(socket_af, socket.SOCK_STREAM)
        try:
            s.connect(connect_param)
        except socket.error:
            s.close()
            continue

        s.send(b"stats\r\n")
        data = s.recv(2048).decode('ascii')
        s.close()

        stats = {}

        for line in data.splitlines():
            info = line.split(" ")

            if info[0] == "STAT":
                try:
                    value = int(info[2])
                except __HOLE__:
                    value = info[2]

                stats[info[1]] = value

        if stats['cmd_get'] == 0:
            stats['hit_rate'] = 0
            stats['miss_rate'] = 0
        else:
            stats['hit_rate'] = 100 * stats['get_hits'] / stats['cmd_get']
            stats['miss_rate'] = 100 * stats['get_misses'] / stats['cmd_get']

        all_stats.append((hostname, stats))

    return all_stats
dataset/ETHPy150Open reviewboard/reviewboard/reviewboard/admin/cache_stats.py/get_cache_stats