Commit b04d8363 by Tran Hoang Viet

VietTH: Implement fragment cache for categories

parent 339cfb67
module CategoriesHelper
def cache_key_for_categories
count = Category.all.size
max_updated_at = Category.maximum(:updated_at).try(:utc).try(:to_s, :number)
"products/all-#{count}-#{max_updated_at}"
end
end
\ No newline at end of file
%h3.title Category
%ul.nav.nav-sidebar
- cache(cache_key_for_categories) do
%h3.title Category
%ul.nav.nav-sidebar
= render partial: '/categories/category', collection: Category.limit(Settings.limit_category).select(Category::JSON_DEFAULT)
\ No newline at end of file
......@@ -30,6 +30,7 @@
.form-group
= f.label :category, class: 'col-sm-2 control-label'
.col-sm-4
- cache("product-new-#{cache_key_for_categories}") do
= f.collection_select :category_id, @categories.decorate, :id, :title, {}, class: 'form-control'
.form-group
......
......@@ -7,6 +7,7 @@
.form-group
= label :query, 'Category: ', class: 'col-sm-2 control-label'
.col-sm-5
- cache("search-#{cache_key_for_categories}") do
= select_tag :category, options_from_collection_for_select(@categories.decorate, :id, :title, params[:category]), {include_blank: '-- Select category --', class: 'form-control chosen-select', multiple: true}
.form-group
= label :query, 'Product price: ', class: 'col-sm-2 control-label'
......
......@@ -11,7 +11,7 @@ Rails.application.configure do
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_controller.perform_caching = true
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment