Check if the aws function response hits the cache or not. If the cache hits:
raises an AwsNoChange exception if do_raise == :raise.
returnes parsed response from the cache if it exists or true otherwise.
If the cache miss or the caching is off then returns false.
# File lib/awsbase/right_awsbase.rb, line 279 def cache_hits?(function, response, do_raise=:raise) result = false if caching? function = function.to_sym # get rid of requestId (this bad boy was added for API 2008-08-08+ and it is uniq for every response) # feb 04, 2009 (load balancer uses 'RequestId' hence use 'i' modifier to hit it also) response = response.sub(%{<requestId>.+?</requestId>}, '') response_md5 = MD5.md5(response).to_s # check for changes unless @cache[function] && @cache[function][:response_md5] == response_md5 # well, the response is new, reset cache data update_cache(function, {:response_md5 => response_md5, :timestamp => Time.now, :hits => 0, :parsed => nil}) else # aha, cache hits, update the data and throw an exception if needed @cache[function][:hits] += 1 if do_raise == :raise raise(AwsNoChange, "Cache hit: #{function} response has not changed since "+ "#{@cache[function][:timestamp].strftime('%Y-%m-%d %H:%M:%S')}, "+ "hits: #{@cache[function][:hits]}.") else result = @cache[function][:parsed] || true end end end result end
Returns true if the describe_xxx responses are being cached
# File lib/awsbase/right_awsbase.rb, line 270 def caching? @params.key?(:cache) ? @params[:cache] : @@caching end
# File lib/awsbase/right_awsbase.rb, line 363 def get_connection(aws_service, request) #:nodoc server_url = "#{request[:protocol]}://#{request[:server]}:#{request[:port]}}" # case @params[:connections].to_s when 'dedicated' @connections_storage ||= {} else # 'dedicated' @connections_storage = (Thread.current[aws_service] ||= {}) end # @connections_storage[server_url] ||= {} @connections_storage[server_url][:last_used_at] = Time.now @connections_storage[server_url][:connection] ||= Rightscale::HttpConnection.new(:exception => RightAws::AwsError, :logger => @logger) # keep X most recent connections (but were used not far than Y minutes ago) connections = 0 @connections_storage.to_a.sort{|i1, i2| i2[1][:last_used_at] <=> i1[1][:last_used_at]}.to_a.each do |i| if i[0] != server_url && (@params[:max_connections] <= connections || i[1][:last_used_at] < Time.now - @params[:connection_lifetime]) # delete the connection from the list @connections_storage.delete(i[0]) # then finish it i[1][:connection].finish((@params[:max_connections] <= connections) ? "out-of-limit" : "out-of-date") rescue nil else connections += 1 end end @connections_storage[server_url][:connection] end
# File lib/awsbase/right_awsbase.rb, line 260 def signed_service_params(aws_secret_access_key, service_hash, http_verb=nil, host=nil, service=nil ) case signature_version.to_s when '0' then AwsUtils::sign_request_v0(aws_secret_access_key, service_hash) when '1' then AwsUtils::sign_request_v1(aws_secret_access_key, service_hash) when '2' then AwsUtils::sign_request_v2(aws_secret_access_key, service_hash, http_verb, host, service) else raise AwsError.new("Unknown signature version (#{signature_version.to_s}) requested") end end
Generated with the Darkfish Rdoc Generator 2.