def fetch_stacks(stack_id = nil)
      cache.locked_action(:stacks_lock) do
        logger.info "Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})"
        if stack_id
          single_stack = connection.stacks.get(stack_id)
          stacks = single_stack ? {single_stack.id => single_stack} : {}
        else
          stacks = Hash[
            connection.stacks.reload.all.map do |stack|
              [stack.id, stack.attributes]
            end
          ]
        end
        if cache[:stacks].value
          existing_stacks = MultiJson.load(cache[:stacks].value)
          # Force common types
          stacks = MultiJson.load(MultiJson.dump(stacks))
          if stack_id
            stacks = existing_stacks.to_smash.deep_merge(stacks)
          else
            # Remove stacks that have been deleted
            stale_ids = existing_stacks.keys - stacks.keys
            stacks = existing_stacks.to_smash.deep_merge(stacks)
            stale_ids.each do |stale_id|
              stacks.delete(stale_id)
            end
          end
        end
        cache[:stacks].value = stacks.to_json
        logger.info "Stack list has been updated from upstream and cached locally"
      end
      @initial_fetch_complete = true
    end
def fetch_stacks(stack_id = nil)
      cache.locked_action(:stacks_lock) do
        logger.info "Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})"
        if stack_id
          single_stack = connection.stacks.get(stack_id)
          stacks = single_stack ? {single_stack.id => single_stack} : {}
        else
          stacks = Hash[
            connection.stacks.reload.all.map do |stack|
              [stack.id, stack.attributes]
            end
          ]
        end
        if cache[:stacks].value
          existing_stacks = MultiJson.load(cache[:stacks].value)
          # Force common types
          stacks = MultiJson.load(MultiJson.dump(stacks))
          if stack_id
            stacks = existing_stacks.to_smash.deep_merge(stacks)
          else
            # Remove stacks that have been deleted
            stale_ids = existing_stacks.keys - stacks.keys
            stacks = existing_stacks.to_smash.deep_merge(stacks)
            stale_ids.each do |stale_id|
              stacks.delete(stale_id)
            end
          end
        end
        cache[:stacks].value = stacks.to_json
        logger.info "Stack list has been updated from upstream and cached locally"
      end
      @initial_fetch_complete = true
    end
Request stack information and store in cache

 @return [TrueClass]