class Multiwoven::Integrations::Source::WatsonxAi::Client

def get_access_token(api_key)

def get_access_token(api_key)
  cache = defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ActiveSupport::Cache::MemoryStore.new
  cache_key = "watsonx_ai_#{api_key}"
  cached_token = cache.read(cache_key)
  if cached_token
    @access_token = cached_token
  else
    new_token = get_iam_token(api_key)
    # max expiration is 3 minutes. No way to make it higher
    cache.write(cache_key, new_token, expires_in: 180)
    @access_token = new_token
  end
end