def _generate_cache_key(ctx, spec_name, platform, configuration):
    """
    Generate a composite key for (optional) spec_name, platform, and configuration
    :param ctx:             The context
    :param spec_name:       name of the spec (or None, use the current spec)
    :param platform:        the platform (or None, use the current platform)
    :param configuration:   the configuration (or None, use the current configuration)
    :return:                The composite key
    """
    if hasattr(ctx, 'env'):
        if not platform:
            platform = ctx.env['PLATFORM']
        if not configuration:
            configuration = ctx.env['CONFIGURATION']
    else:
        if not platform:
            platform = 'none'
        if not configuration:
            configuration = 'none'
    composite_key = spec_name + '_' + platform + '_' + configuration
    return composite_key