module Card::View::Cache::CacheAction
determine action to be used in fetch
Constants
- ACTIVE_CACHE_LEVEL
Private Instance Methods
Source
# File lib/card/view/cache/cache_action.rb, line 76 def active_cache_action active_cache_ok? ? active_cache_action_from_setting : :stub end
@return [Symbol]
Source
# File lib/card/view/cache/cache_action.rb, line 115 def active_cache_action_from_setting level = ACTIVE_CACHE_LEVEL[cache_setting] level || raise("unknown cache setting: #{cache_setting}") end
determine the cache action from the cache setting (assuming cache status is “active”) @return [Symbol] cache action
Source
# File lib/card/view/cache/cache_action.rb, line 81 def active_cache_ok? return false unless cacheable_card? && clean_enough_to_cache? return true if normalized_options[:skip_perms] active_cache_permissible? end
@return [True/False]
Source
# File lib/card/view/cache/cache_action.rb, line 99 def active_cache_permissible? case view_perms when :none then true when view_perm_context then true when *Permission::CRUD then format.anyone_can?(view_perms) else false end end
apply any permission checks required by view. (do not cache views with nuanced permissions)
Source
# File lib/card/view/cache/cache_action.rb, line 17 def cache_action log_cache_action do send "#{cache_status}_cache_action" end end
course of action based on config/status/options @return [Symbol] :yield, :cache_yield, or
Source
# File lib/card/view/cache/cache_action.rb, line 48 def cache_on? Card.config.view_cache && format.class.view_caching? end
@return [True/False]
Source
# File lib/card/view/cache/cache_action.rb, line 124 def cache_setting @cache_setting ||= format.view_cache_setting requested_view end
@return [Symbol] :standard, :always, or :never
Source
# File lib/card/view/cache/cache_action.rb, line 32 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
@return [Symbol] :off, :active, or :free
Source
# File lib/card/view/cache/cache_action.rb, line 88 def cacheable_card? return true if caching == :deep || parent.present? # a parent voo means we're still in the same card return false unless (superformat_card = format.parent&.card) superformat_card.name == card.name.left_name end
Source
# File lib/card/view/cache/cache_action.rb, line 130 def clean_enough_to_cache? # requested_view == ok_view && !card.unknown? && !card.db_content_changed? requested_view == ok_view && card.view_cache_clean? end
altered view requests and altered cards are not cacheable @return [True/False]
Source
# File lib/card/view/cache/cache_action.rb, line 62 def free_cache_action free_cache_ok? ? :cache_yield : :yield end
@return [Symbol]
Source
# File lib/card/view/cache/cache_action.rb, line 67 def free_cache_ok? !cache_setting.in?(%i[default never]) && clean_enough_to_cache? end
@return [True/False]
Source
# File lib/card/view/cache/cache_action.rb, line 23 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
Source
# File lib/card/view/cache/cache_action.rb, line 53 def off_cache_action :yield end
always skip all the magic
Source
# File lib/card/view/cache/cache_action.rb, line 108 def view_perm_context parent&.view_perms || format.parent&.voo&.view_perms end