Module: Magick::RequestStoreIntegration::ClassMethods

Defined in:
lib/magick/rails/railtie.rb

Instance Method Summary collapse

Instance Method Details

#enabled?(feature_name, context = {}) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/magick/rails/railtie.rb', line 129

def enabled?(feature_name, context = {})
  # Check request store cache first
  if defined?(RequestStore)
    cache_key = "#{feature_name}:#{context.hash}"
    cached = RequestStore.store[:magick_features]&.[](cache_key)
    return cached unless cached.nil?
  end

  # Check feature
  result = super(feature_name, context)

  # Cache in request store
  if defined?(RequestStore)
    RequestStore.store[:magick_features] ||= {}
    RequestStore.store[:magick_features][cache_key] = result
  end

  result
end