@@ -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 } >>\n to <<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