Module: RecurlyApi::Caching
- Included in:
- Client
- Defined in:
- lib/recurly_api/caching.rb
Overview
Don’t perform caching for non-rails projects
Constant Summary collapse
- CACHE_SETTINGS =
default settings for caching, every GET request is cached by default with default expiry_time 300 seconds(5 minutes)
{ bypass: false, default_expiry: 300, plan_expiry: 300, subscription_expiry: 5 }.freeze
Instance Attribute Summary collapse
-
#cache_expires_in ⇒ Object
accessor for getter and setter methods.
-
#cache_key ⇒ Object
accessor for getter and setter methods.
-
#ignore_caching ⇒ Object
accessor for getter and setter methods.
Instance Method Summary collapse
-
#cache ⇒ Object
Usage examples to perform caching in RecurlyApi:Client cache.write(‘key’, ‘val’, expires_in: 30) cache.fetch(‘key’).
- #cache_key_with_prefix ⇒ Object
-
#cache_prefix_name ⇒ Object
tribune_recurly_api GEM related cache saved as ‘tribune_recurly_api.<cache_key>’ in cache_store.
-
#caching_enabled? ⇒ Boolean
for non-rails applications do not perform caching on Recurly Response’s perform caching only if it is enabled in Rails application.
-
#check_logs_for_caching_info ⇒ Object
TODO: remove below method once integration testing is done.
- #fetch_response_from_cache ⇒ Object
- #ignore_caching? ⇒ Boolean (also: #bypass_caching?)
- #write_final_resp_to_cache ⇒ Object
Instance Attribute Details
#cache_expires_in ⇒ Object
accessor for getter and setter methods
8 9 10 |
# File 'lib/recurly_api/caching.rb', line 8 def cache_expires_in @cache_expires_in end |
#cache_key ⇒ Object
accessor for getter and setter methods
8 9 10 |
# File 'lib/recurly_api/caching.rb', line 8 def cache_key @cache_key end |
#ignore_caching ⇒ Object
accessor for getter and setter methods
8 9 10 |
# File 'lib/recurly_api/caching.rb', line 8 def ignore_caching @ignore_caching end |
Instance Method Details
#cache ⇒ Object
Usage examples to perform caching in RecurlyApi:Client cache.write(‘key’, ‘val’, expires_in: 30) cache.fetch(‘key’)
21 22 23 |
# File 'lib/recurly_api/caching.rb', line 21 def cache @cache ||= defined?(Rails) ? Rails.cache : nil end |
#cache_key_with_prefix ⇒ Object
36 37 38 |
# File 'lib/recurly_api/caching.rb', line 36 def cache_key_with_prefix "#{cache_prefix_name}#{cache_key}" end |
#cache_prefix_name ⇒ Object
tribune_recurly_api GEM related cache saved as ‘tribune_recurly_api.<cache_key>’ in cache_store
32 33 34 |
# File 'lib/recurly_api/caching.rb', line 32 def cache_prefix_name 'tribune_recurly_api.' end |
#caching_enabled? ⇒ Boolean
for non-rails applications do not perform caching on Recurly Response’s perform caching only if it is enabled in Rails application
27 28 29 |
# File 'lib/recurly_api/caching.rb', line 27 def caching_enabled? !cache.nil? && Rails.application.config.action_controller.perform_caching end |
#check_logs_for_caching_info ⇒ Object
TODO: remove below method once integration testing is done
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/recurly_api/caching.rb', line 55 def check_logs_for_caching_info # logger.info("#{logger_heading}: ----> caching_enabled?: #{caching_enabled?}") # # logger.info("#{logger_heading}: ----> ignore_caching?: #{ignore_caching?}") # logger.info("#{logger_heading}: ----> bypass_caching?: #{bypass_caching?}") # logger.info("#{logger_heading}: ----> http_method: #{http_method} -- #{http_method.class}") # logger.info("#{logger_heading}: ----> cache_expires_in: #{cache_expires_in}") # logger.info("#{logger_heading}: ----> cache_key: #{cache_key} -- #{cache_key.class}") # logger.info("#{logger_heading}: ----> final response: #{final_response || fetch_response_from_cache}") logger.info("#{logger_heading}: ----> ratelimit_retries: #{ratelimit_retries}") end |
#fetch_response_from_cache ⇒ Object
49 50 51 52 |
# File 'lib/recurly_api/caching.rb', line 49 def fetch_response_from_cache # cache.exist?(cache_key_with_prefix) # check if cache already exists or not for requested API call cache.fetch(cache_key_with_prefix) # returns nil if cache not exists for requested API call. end |
#ignore_caching? ⇒ Boolean Also known as: bypass_caching?
40 41 42 |
# File 'lib/recurly_api/caching.rb', line 40 def ignore_caching? @ignore_caching end |
#write_final_resp_to_cache ⇒ Object
45 46 47 |
# File 'lib/recurly_api/caching.rb', line 45 def write_final_resp_to_cache cache.write(cache_key_with_prefix, final_response, expires_in: cache_expires_in) end |