lib/awsbase/right_awsbase.rb
# 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+.
Check if the aws function response hits the cache or not.
Check if the aws function response hits the cache or not .
def cache_hits?(function, response, do_raise=:raise)
      result = false
      if caching?
        function = function.to_sym
        response = response.sub(%r{<requestId>.+?</requestId>}i, '')
        response_md5 = Digest::MD5::new.update(response).to_s
        unless @cache[function] && @cache[function][:response_md5] == response_md5
          update_cache(function, {:response_md5 => response_md5, 
                                  :timestamp    => Time.now, 
                                  :hits         => 0, 
                                  :parsed       => nil})
        else
          @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
def cache_hits? ( function , response , do_raise = :raise ) result = false if caching? function = function . to_sym response = response . sub ( %r{ <requestId>.+?</requestId> }i , '' ) response_md5 = Digest :: MD5 :: new . update ( response ) . to_s unless @cache [ function ] && @cache [ function ] [ :response_md5 ] == response_md5 update_cache ( function , { :response_md5 => response_md5 , :timestamp => Time . now , :hits => 0 , :parsed => nil } ) else @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
Check if the aws function response hits the cache or not.
Check if the aws function response hits the cache or not .
# 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) # this should work for both ruby 1.8.x and 1.9.x # check for changes # well, the response is new, reset cache data # aha, cache hits, update the data and throw an exception if needed
function
<not_specific>
response
<not_specific>
do_raise
<not_specific>