module Card::View::Cache::CacheAction
determine action to be used in fetch
Constants
- ACTIVE_CACHE_LEVEL
Private Instance Methods
active_cache_action()
click to toggle source
@return [Symbol]
# File lib/card/view/cache/cache_action.rb, line 69 def active_cache_action active_cache_ok? ? active_cache_action_from_setting : :stub end
active_cache_action_from_setting()
click to toggle source
determine the cache action from the cache setting (assuming cache status is “active”) @return [Symbol] cache action
# File lib/card/view/cache/cache_action.rb, line 95 def active_cache_action_from_setting level = ACTIVE_CACHE_LEVEL[cache_setting] level || raise("unknown cache setting: #{cache_setting}") end
active_cache_ok?()
click to toggle source
@return [True/False]
# File lib/card/view/cache/cache_action.rb, line 74 def active_cache_ok? return false unless parent && clean_enough_to_cache? return true if normalized_options[:skip_perms] active_cache_permissible? end
active_cache_permissible?()
click to toggle source
apply any permission checks required by view. (do not cache views with nuanced permissions)
# File lib/card/view/cache/cache_action.rb, line 83 def active_cache_permissible? case view_perms when :none then true when parent.view_perms then true when *Permission::CRUD then format.anyone_can?(view_perms) else false end end
cache_action()
click to toggle source
course of action based on config/status/options @return [Symbol] :yield, :cache_yield, or
# File lib/card/view/cache/cache_action.rb, line 10 def cache_action log_cache_action do send "#{cache_status}_cache_action" end end
cache_on?()
click to toggle source
@return [True/False]
# File lib/card/view/cache/cache_action.rb, line 41 def cache_on? Card.config.view_cache && format.class.view_caching? end
cache_setting()
click to toggle source
@return [Symbol] :standard, :always, or :never
# File lib/card/view/cache/cache_action.rb, line 107 def cache_setting format.view_cache_setting requested_view end
cache_status()
click to toggle source
@return [Symbol] :off, :active, or :free
# File lib/card/view/cache/cache_action.rb, line 25 def cache_status case when !cache_on? :off # view caching is turned off, format- or system-wide when cache_active? :active # another view cache is in progress (current view is inside it) else :free # no other cache in progress end end
clean_enough_to_cache?()
click to toggle source
altered view requests and altered cards are not cacheable @return [True/False]
# File lib/card/view/cache/cache_action.rb, line 113 def clean_enough_to_cache? # requested_view == ok_view && !card.unknown? && !card.db_content_changed? requested_view == ok_view && card.view_cache_clean? end
free_cache_action()
click to toggle source
@return [Symbol]
# File lib/card/view/cache/cache_action.rb, line 55 def free_cache_action free_cache_ok? ? :cache_yield : :yield end
free_cache_ok?()
click to toggle source
@return [True/False]
# File lib/card/view/cache/cache_action.rb, line 60 def free_cache_ok? cache_setting != :never && clean_enough_to_cache? end
log_cache_action() { || ... }
click to toggle source
# File lib/card/view/cache/cache_action.rb, line 16 def log_cache_action yield # TODO: make configurable # ...or better yet, integrate into performance logger... # Rails.logger.warn "VIEW CACHE #{cache_active? ? '-->' : ''}[#{action}] "\ # "(#{card.name}##{requested_view})" end
off_cache_action()
click to toggle source
always skip all the magic
# File lib/card/view/cache/cache_action.rb, line 46 def off_cache_action :yield end