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)


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/magick/rails/railtie.rb', line 149

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