Class: ActiveSupport::Cache::S3CacheStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::S3CacheStore
- Defined in:
- lib/active_support/cache/s3_cache_store.rb
Overview
S3 Cache Store
A cache store implementation which stores everything on the Amazon S3 Bucket.
Constant Summary collapse
- OBJECT_KEY_MAX_SIZE =
max is 1024, plus some room
900
Instance Attribute Summary collapse
-
#s3_client ⇒ Object
readonly
Returns the value of attribute s3_client.
Instance Method Summary collapse
- #clear(options = nil) ⇒ Object
- #decrement(name, amount = 1, options = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #increment(name, amount = 1, options = nil) ⇒ Object
-
#initialize(bucket:, region: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"], prefix: "", **options) ⇒ S3CacheStore
constructor
A new instance of S3CacheStore.
Constructor Details
#initialize(bucket:, region: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"], prefix: "", **options) ⇒ S3CacheStore
Returns a new instance of S3CacheStore.
21 22 23 24 25 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 21 def initialize(bucket:, region: ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"], prefix: "", **) super() @s3_client = ::S3CacheStore::S3Client.new(bucket: bucket, region: region) @prefix = prefix.is_a?(Pathname) ? prefix : Pathname(prefix) end |
Instance Attribute Details
#s3_client ⇒ Object (readonly)
Returns the value of attribute s3_client.
17 18 19 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 17 def s3_client @s3_client end |
Instance Method Details
#clear(options = nil) ⇒ Object
41 42 43 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 41 def clear( = nil) s3_client.clear(@prefix.to_s) if @prefix end |
#decrement(name, amount = 1, options = nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 34 def decrement(name, amount = 1, = nil) current = read(name, ) value = (current&.to_i || 0) - amount write(name, value, ) value end |
#delete_matched(matcher, options = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 45 def delete_matched(matcher, = nil) = () matcher = key_matcher(matcher, ) instrument(:delete_matched, matcher.inspect) do s3_client.list_objects(@prefix.to_s).each do |object| s3_client.delete_object(object.key) if object.key.match(matcher) end end end |
#increment(name, amount = 1, options = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/active_support/cache/s3_cache_store.rb', line 27 def increment(name, amount = 1, = nil) current = read(name, ) value = (current&.to_i || 0) + amount write(name, value, ) value end |