You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::S3::BucketRegionCache

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

Instance Method Summary collapse

Constructor Details

#initializeBucketRegionCache

Returns a new instance of BucketRegionCache.



7
8
9
10
11
# File 'aws-sdk-core/lib/aws-sdk-core/s3/bucket_region_cache.rb', line 7

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.

S3::BUCKET_REGIONS.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.



31
32
33
34
35
36
37
# File 'aws-sdk-core/lib/aws-sdk-core/s3/bucket_region_cache.rb', line 31

def bucket_added(&block)
  if block
    @mutex.synchronize { @listeners << block }
  else
    raise ArgumentError, 'missing required block'
  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.



66
67
68
69
70
# File 'aws-sdk-core/lib/aws-sdk-core/s3/bucket_region_cache.rb', line 66

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