Class: Alephant::Broker::Cache::CachedObject
- Inherits:
-
Object
- Object
- Alephant::Broker::Cache::CachedObject
- Includes:
- Logger
- Defined in:
- lib/alephant/broker/cache/cached_object.rb
Constant Summary collapse
- DEFAULT_TTL =
10
Instance Attribute Summary collapse
-
#s3_obj ⇒ Object
readonly
Returns the value of attribute s3_obj.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(obj) ⇒ CachedObject
constructor
A new instance of CachedObject.
- #to_h(obj = nil) ⇒ Object
- #ttl ⇒ Object
- #update(obj) ⇒ Object
- #updated ⇒ Object
Constructor Details
#initialize(obj) ⇒ CachedObject
Returns a new instance of CachedObject.
13 14 15 16 17 18 19 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 13 def initialize(obj) logger.debug(event: 'SettingCachedObject', content: obj, method: "#{self.class}#initialize") @s3_obj = obj end |
Instance Attribute Details
#s3_obj ⇒ Object (readonly)
Returns the value of attribute s3_obj.
9 10 11 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 9 def s3_obj @s3_obj end |
Instance Method Details
#expired? ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 45 def expired? result = (updated + ttl) < Time.now logger.info(event: 'Expired?', updated: updated, ttl: ttl, updated_plus_ttl: (updated + ttl), now: Time.now, result: result, method: "#{self.class}#expired?") result end |
#to_h(obj = nil) ⇒ Object
59 60 61 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 59 def to_h(obj = nil) obj || s3_obj end |
#ttl ⇒ Object
38 39 40 41 42 43 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 38 def ttl Integer([:ttl] || ['ttl']) rescue TypeError => error logger.error(event: 'NonIntegerTTLError', method: "#{self.class}#ttl", error: error) Integer(Broker.config[:revalidate_cache_ttl] || DEFAULT_TTL) end |
#update(obj) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 21 def update(obj) logger.debug(event: 'UpdatingCachedObject', old_content: @s3_obj, new_content: obj, method: "#{self.class}#update") @s3_obj = obj end |
#updated ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/alephant/broker/cache/cached_object.rb', line 30 def updated time = [:'head_Last-Modified'] Time.parse(time) rescue TypeError, ArgumentError => error logger.error(event: 'CachedObjectLastModifiedError', method: "#{self.class}#updated", error: error) Time.now end |