Class: Aws::S3::BucketRegionCache

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-s3/lib/aws-sdk-s3/bucket_region_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeBucketRegionCache

Returns a new instance of BucketRegionCache.



9
10
11
12
13
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/bucket_region_cache.rb', line 9

def initialize
  @regions = {}
  @listeners = []
  @mutex = Mutex.new
end

Instance Method Details

#bucket_added(&block) ⇒ void

This method returns an undefined value.

Registers a block as a callback. This listener is called when a new bucket/region pair is added to the cache.

Aws::S3.bucket_region_cache.bucket_added do |bucket_name, region_name|
  # ...
end

This happens when a request is made against the classic endpoint, "s3.amazonaws.com" and an error is returned requiring the request to be resent with Signature Version 4. At this point, multiple requests are made to discover the bucket region so that a v4 signature can be generated.

An application can register listeners here to avoid these extra requests in the future. By constructing an Client with the proper region, a proper signature can be generated and redirects avoided.



33
34
35
36
37
38
39
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/bucket_region_cache.rb', line 33

def bucket_added(&block)
  if block
    @mutex.synchronize { @listeners << block }
  else
    raise ArgumentError, 'missing required block'
  end
end

#key?(key) ⇒ Boolean

Parameters:

  • key (String)

Returns:

  • (Boolean)


64
65
66
67
68
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/bucket_region_cache.rb', line 64

def key?(key)
  @mutex.synchronize do
    @regions.key?(key)
  end
end

#to_hashHash Also known as: to_h

Returns a hash of cached bucket names and region names.

Returns:

  • (Hash)

    Returns a hash of cached bucket names and region names.



76
77
78
79
80
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/bucket_region_cache.rb', line 76

def to_hash
  @mutex.synchronize do
    @regions.dup
  end
end