Module: RailsOnboarding::Caching
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails_onboarding/caching.rb
Overview
Caching module for improving performance of onboarding operations
This module provides caching capabilities for:
- Configuration data
- User onboarding state
- Step information
- Milestone data
By default, uses Rails.cache with configurable TTL values
Instance Method Summary collapse
-
#cached_achieved_milestones(ttl: 600) ⇒ Array<String>
Get cached milestone achievements.
-
#cached_available_tooltips(ttl: 600) ⇒ Hash
Get cached available tooltips.
-
#cached_current_onboarding_step(ttl: 300) ⇒ Hash?
Get cached current onboarding step.
-
#cached_needs_onboarding?(ttl: 60) ⇒ Boolean
Check if user needs onboarding (cached).
-
#cached_onboarding_progress(ttl: 300) ⇒ Integer
Get cached onboarding progress.
-
#clear_onboarding_cache ⇒ Object
Clear all caches for this user.
Instance Method Details
#cached_achieved_milestones(ttl: 600) ⇒ Array<String>
Get cached milestone achievements
96 97 98 99 100 101 102 103 |
# File 'lib/rails_onboarding/caching.rb', line 96 def cached_achieved_milestones(ttl: 600) return achieved_milestones if has_dirty_milestone_attributes? cache_key = "rails_onboarding:user:#{id}:milestones" Rails.cache.fetch(cache_key, expires_in: ttl) do achieved_milestones end end |
#cached_available_tooltips(ttl: 600) ⇒ Hash
Get cached available tooltips
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rails_onboarding/caching.rb', line 109 def cached_available_tooltips(ttl: 600) return {} unless RailsOnboarding.configuration.enable_tooltips cache_key = "rails_onboarding:user:#{id}:available_tooltips" Rails.cache.fetch(cache_key, expires_in: ttl) do tooltips = {} RailsOnboarding.configuration.feature_tooltips.each do |feature, config| tooltips[feature] = config if show_feature_tooltip?(feature) end tooltips end end |
#cached_current_onboarding_step(ttl: 300) ⇒ Hash?
Get cached current onboarding step
83 84 85 86 87 88 89 90 |
# File 'lib/rails_onboarding/caching.rb', line 83 def cached_current_onboarding_step(ttl: 300) return current_onboarding_step if has_dirty_onboarding_attributes? cache_key = "rails_onboarding:user:#{id}:current_step" Rails.cache.fetch(cache_key, expires_in: ttl) do current_onboarding_step end end |
#cached_needs_onboarding?(ttl: 60) ⇒ Boolean
Check if user needs onboarding (cached)
135 136 137 138 139 140 141 142 |
# File 'lib/rails_onboarding/caching.rb', line 135 def cached_needs_onboarding?(ttl: 60) return needs_onboarding? if has_dirty_onboarding_attributes? cache_key = "rails_onboarding:user:#{id}:needs_onboarding" Rails.cache.fetch(cache_key, expires_in: ttl) do needs_onboarding? end end |
#cached_onboarding_progress(ttl: 300) ⇒ Integer
Get cached onboarding progress
70 71 72 73 74 75 76 77 |
# File 'lib/rails_onboarding/caching.rb', line 70 def cached_onboarding_progress(ttl: 300) return onboarding_progress if has_dirty_onboarding_attributes? cache_key = "rails_onboarding:user:#{id}:progress" Rails.cache.fetch(cache_key, expires_in: ttl) do onboarding_progress end end |
#clear_onboarding_cache ⇒ Object
Clear all caches for this user
123 124 125 126 127 128 129 |
# File 'lib/rails_onboarding/caching.rb', line 123 def clear_onboarding_cache Rails.cache.delete("rails_onboarding:user:#{id}:progress") Rails.cache.delete("rails_onboarding:user:#{id}:current_step") Rails.cache.delete("rails_onboarding:user:#{id}:milestones") Rails.cache.delete("rails_onboarding:user:#{id}:available_tooltips") Rails.cache.delete("rails_onboarding:user:#{id}:needs_onboarding") end |