/**
 * @param string $type
 * @param $api
 * @param null $passed
 * @param array $return
 * @param null $page
 * @param bool $return_error Whether to return exception object
 *
 * @return array|bool
 */
function constant_contact_old_api_get_all($type = 'Events', &$api, $passed = null, &$return = array(), $page = null, $return_error = false)
{
    $key = constant_contact_cache_key('all_' . $type, $passed);
    if (!constant_contact_refresh_cache($type) && ($cached = get_transient($key))) {
        return $cached;
    }
    try {
        ob_start();
        if (!empty($passed)) {
            $items = $api->{"get{$type}"}($passed, $page);
        } else {
            $items = $api->{"get{$type}"}($page);
        }
        $error = ob_get_clean();
        if ($error) {
            do_action('ctct_error', 'Get All Events Exception', $error);
        }
        // If no results
        if (empty($items[strtolower($type)])) {
            return $return;
        } else {
            // Otherwise, add items using the startdate time as the key for sorting below
            foreach ($items[strtolower($type)] as $item) {
                $allkey = isset($item->startDate) ? strtotime($item->startDate) : null;
                $return[$allkey] = $item;
            }
            // Sort by event date
            krsort($return);
            if (!empty($items['nextLink'])) {
                constant_contact_old_api_get_all($type, $api, $passed, $return, $items['nextLink']);
            }
            set_transient($key, $return, apply_filters('constant_contact_cache_age', HOUR_IN_SECONDS * 6));
        }
    } catch (Exception $e) {
        do_action('ctct_error', 'Get All Events Exception', $e->getMessage());
        $return = $return_error ? $e : false;
    }
    return $return;
}
 function refreshCache($type = '')
 {
     return constant_contact_refresh_cache($type);
 }