docbrown/app/controllers/concerns/edge_cache_safety_check.rb
Andy Zhao 3b81172c56
Remove docs from repo ✂✂✂ (#14579)
* Remove docs ✂✂✂✂

* Remove all references to docs and gitdocs

* Update docs.forem.com to developers.forem.com

* Remove .gitdocs_build/

* Update yarn.lock
2021-08-23 17:23:42 -04:00

18 lines
787 B
Ruby

# Included in Application Controller to monkey patch Devise::Controllers::Helpers#current_user
# https://github.com/heartcombo/devise/blob/5d5636f03ac19e8188d99c044d4b5e90124313af/lib/devise/controllers/helpers.rb#L103
module EdgeCacheSafetyCheck
extend ActiveSupport::Concern
CANNOT_USE_CURRENT_USER = "You may not use current_user in this cached code path.".freeze
def current_user
# In production, current_user will cause a cache leak if it's placed within an edge-cached code path.
# More information here:
# https://developers.forem.com/technical-overview/architecture/#we-cache-many-content-pages-on-the-edge
return super unless RequestStore.store[:edge_caching_in_place]
return if session_current_user_id.blank?
CANNOT_USE_CURRENT_USER
end
end