Module: Plugins::FrontCache::FrontCacheHelper
- Included in:
- AdminController
- Defined in:
- app/apps/plugins/front_cache/front_cache_helper.rb
Instance Method Summary collapse
-
#front_cache_before_load ⇒ Object
expire cache for a page after comment registered or updated.
-
#front_cache_clean ⇒ Object
clear all frontend cache files.
- #front_cache_front_after_load ⇒ Object
-
#front_cache_front_before_load ⇒ Object
save as cache all pages configured on settings of this plugin for public users.
-
#front_cache_on_active(plugin) ⇒ Object
on install plugin.
-
#front_cache_on_inactive(plugin) ⇒ Object
on uninstall plugin.
-
#front_cache_on_render(args) ⇒ Object
cache actions (for logged users).
- #front_cache_plugin_options(arg) ⇒ Object
-
#front_cache_post_requests ⇒ Object
save as cache all post requests.
Instance Method Details
#front_cache_before_load ⇒ Object
expire cache for a page after comment registered or updated
75 76 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 75 def front_cache_before_load end |
#front_cache_clean ⇒ Object
clear all frontend cache files
91 92 93 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 91 def front_cache_clean FileUtils.rm_rf(front_cache_plugin_get_path) # clear site pages cache end |
#front_cache_front_after_load ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 43 def front_cache_front_after_load cache_key = request.fullpath.parameterize if @_plugin_do_cache && !flash.keys.present? args = {data: response.body .gsub(/csrf-token" content="(.*?)"/, 'csrf-token" content="{{form_authenticity_token}}"') .gsub(/name="authenticity_token" value="(.*?)"/, 'name="authenticity_token" value="{{form_authenticity_token}}"')} hooks_run('front_cache_writing_cache', args) front_cache_plugin_cache_create(cache_key, args[:data]) Rails.logger.info "Camaleon CMS - cache saved as: #{front_cache_plugin_get_path(cache_key)}" end end |
#front_cache_front_before_load ⇒ Object
save as cache all pages configured on settings of this plugin for public users
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 4 def front_cache_front_before_load if current_site.get_option("refresh_cache") # clear cache every restart server front_cache_clean current_site.set_option("refresh_cache", false) end return if signin? || Rails.env == "development" || Rails.env == "test" || !request.get? # avoid cache if current visitor is logged in or development environment cache_key = request.fullpath.parameterize if !flash.keys.present? && front_cache_exist?(cache_key) # recover cache file Rails.logger.info "Camaleon CMS - readed cache: #{front_cache_plugin_get_path(cache_key)}" response.headers['PLUGIN_FRONT_CACHE'] = 'TRUE' args = {data: front_cache_get(cache_key).gsub("{{form_authenticity_token}}", form_authenticity_token)}; hooks_run('front_cache_reading_cache', args) render text: args[:data] return end @caches = current_site.("front_cache_elements") @_plugin_do_cache = false if @caches[:paths].include?(request.original_url) || @caches[:paths].include?(request.path_info) || front_cache_plugin_match_path_patterns?(request.original_url, request.path_info) || (params[:action] == 'index' && params[:controller] == 'camaleon_cms/frontend' && @caches[:home].present?) # cache paths and home page @_plugin_do_cache = true elsif params[:action] == "post" && params[:controller] == 'camaleon_cms/frontend' && !params[:draft_id].present? begin post = current_site.the_posts.find_by_slug(params[:slug]).decorate if post.can_visit? && post.visibility != "private" post = post if (@caches[:skip_posts] || []).include?(post.id.to_s) @_plugin_do_cache = false else @_plugin_do_cache = true if (@caches[:post_types] || []).include?(post.post_type_id.to_s) || (@caches[:posts] || []).include?(post.id.to_s) end end rescue # skip post not found end end response.headers['PLUGIN_FRONT_CACHE'] = 'TRUE' if @_plugin_do_cache end |
#front_cache_on_active(plugin) ⇒ Object
on install plugin
56 57 58 59 60 61 62 63 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 56 def front_cache_on_active(plugin) current_site.("front_cache_elements", {paths: [], posts: [], post_types: [current_site.post_types.where(slug: "page").first.id], skip_posts: [], home: true, cache_login: true}) unless current_site.("front_cache_elements", nil).present? end |
#front_cache_on_inactive(plugin) ⇒ Object
on uninstall plugin
66 67 68 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 66 def front_cache_on_inactive(plugin) # current_site.delete_meta("front_cache_elements") end |
#front_cache_on_render(args) ⇒ Object
cache actions (for logged users)
71 72 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 71 def front_cache_on_render(args) end |
#front_cache_plugin_options(arg) ⇒ Object
78 79 80 81 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 78 def (arg) arg[:links] << link_to(t('plugin.front_cache.settings'), admin_plugins_front_cache_settings_path) arg[:links] << link_to(t('plugin.front_cache.clean_cache'), admin_plugins_front_cache_clean_path) end |
#front_cache_post_requests ⇒ Object
save as cache all post requests
84 85 86 87 88 |
# File 'app/apps/plugins/front_cache/front_cache_helper.rb', line 84 def front_cache_post_requests if (request.post? || request.patch?) front_cache_clean() end end |