Skip to content

Commit cf2766a

Browse files
committed
fixed cache clearing of categories upon creation / update
1 parent 23419b0 commit cf2766a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

app/controllers/categories_controller.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def create
4747
AuditLog.admin_audit(event_type: 'category_create', related: @category, user: current_user,
4848
comment: "<<Category #{before}>>")
4949
flash[:success] = 'Your category was created.'
50-
Rails.cache.delete "#{RequestContext.community_id}/header_categories"
51-
Rails.cache.delete 'categories/by_lowercase_name'
52-
Rails.cache.delete 'categories/by_id'
50+
clear_categories_cache
5351
redirect_to category_path(@category)
5452
else
5553
flash[:danger] = 'There were some errors while trying to save your category.'
@@ -69,9 +67,7 @@ def update
6967
AuditLog.admin_audit(event_type: 'category_update', related: @category, user: current_user,
7068
comment: "from <<Category #{before}>>\nto <<Category #{after}>>")
7169
flash[:success] = 'Your category was updated.'
72-
Rails.cache.delete "#{RequestContext.community_id}/header_categories"
73-
Rails.cache.delete 'categories/by_lowercase_name'
74-
Rails.cache.delete 'categories/by_id'
70+
clear_categories_cache
7571
redirect_to category_path(@category)
7672
else
7773
flash[:danger] = 'There were some errors while trying to save your category.'
@@ -207,6 +203,12 @@ def set_list_posts
207203
@posts = @posts.paginate(page: params[:page], per_page: 50).order(sort_param)
208204
end
209205

206+
def clear_categories_cache
207+
Rails.cache.delete 'header_categories'
208+
Rails.cache.delete 'categories/by_lowercase_name'
209+
Rails.cache.delete 'categories/by_id'
210+
end
211+
210212
# Updates last visit cache for a given category
211213
# @param category [Category] category to update
212214
# @return [Boolean] whether the cache entry is deleted

0 commit comments

Comments
 (0)