human
Complete this python program:
def cache_size(mb=True):
assistant
#Here is the Python code you requested.

    """Calculate statistics about the cache.
    Note: we cannot get reliable memory statistics from the cache -
    whereas we could do `getsizof` each object in cache, the result is
    highly imprecise and for a large number of objects the result is
    many times larger than the actual memory usage of the entire server;
    Python is clearly reusing memory behind the scenes that we cannot
    catch in an easy way here.  Ideas are appreciated. /Griatch
    Returns:
    total_num, {objclass:total_num, ...}
    """
    numtotal = [0]
    classdict = {}
    def get_recurse(submodels):
        for submodel in submodels:
            subclasses = submodel.__subclasses__()
            if (not subclasses):
                num = len(submodel.get_all_cached_instances())
                numtotal[0] += num
                classdict[submodel.__dbclass__.__name__] = num
            else:
                get_recurse(subclasses)
    get_recurse(SharedMemoryModel.__subclasses__())
    return (numtotal[0], classdict)