def resid_factory(source, name='generic-%s', resid='auto'):
    """ create a cache resource identifier on demand

    :param source: the producer of the data, can be any type as long as it
        has a `id` member
    :param name: str, format string for the resource Id string if it is to be
        generated
    :param resid: str, optional. If 'auto' (the default), generate a resource
        id from the `source` and the `name` parameters. Otherwise, the value of
        `resid` itself is returned. If `None` caching will be disabled.

    :returns string: a (hopefully) unique id to save the resource in the cache
    """
    if resid == 'auto':
        return name.format(id=source.id)

    return resid