Class: PubSubModelSync::PayloadCacheOptimizer
- Defined in:
- lib/pub_sub_model_sync/payload_cache_optimizer.rb
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid delivering unnecessary notifications.
-
#payload ⇒ Object
readonly
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid delivering unnecessary notifications.
-
#required_attrs ⇒ Object
readonly
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid delivering unnecessary notifications.
Instance Method Summary collapse
- #call ⇒ :already_sent|Payload
-
#initialize(payload) ⇒ PayloadCacheOptimizer
constructor
A new instance of PayloadCacheOptimizer.
Methods inherited from Base
Constructor Details
#initialize(payload) ⇒ PayloadCacheOptimizer
Returns a new instance of PayloadCacheOptimizer.
11 12 13 14 |
# File 'lib/pub_sub_model_sync/payload_cache_optimizer.rb', line 11 def initialize(payload) @payload = payload @cache_key = "pubsub/#{payload.headers[:internal_key]}/#{payload.headers[:topic_name]}" end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid
delivering unnecessary notifications.
Uses Rails.cache to retrieve previous delivered data.
8 9 10 |
# File 'lib/pub_sub_model_sync/payload_cache_optimizer.rb', line 8 def cache_key @cache_key end |
#payload ⇒ Object (readonly)
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid
delivering unnecessary notifications.
Uses Rails.cache to retrieve previous delivered data.
8 9 10 |
# File 'lib/pub_sub_model_sync/payload_cache_optimizer.rb', line 8 def payload @payload end |
#required_attrs ⇒ Object (readonly)
Optimizes payload data to deliver only the required ones and the changed ones and thus avoid
delivering unnecessary notifications.
Uses Rails.cache to retrieve previous delivered data.
8 9 10 |
# File 'lib/pub_sub_model_sync/payload_cache_optimizer.rb', line 8 def required_attrs @required_attrs end |
Instance Method Details
#call ⇒ :already_sent|Payload
17 18 19 20 21 22 23 24 25 |
# File 'lib/pub_sub_model_sync/payload_cache_optimizer.rb', line 17 def call backup_data = payload.data.clone return payload if cache_disabled? return :already_sent if previous_payload_data == payload.data optimize_payload if optimization_allowed? Rails.cache.write(cache_key, backup_data, expires_in: 1.week) payload end |