dev_forum
daiao 5 years ago
commit 9feb0d3869

@ -3,8 +3,7 @@ class Department < ApplicationRecord
has_many :department_members, dependent: :destroy
after_create_commit :reset_data_cache
after_update_commit :reset_data_cache
after_commit :reset_data_cache
def self.cached_names_data(school)
Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do
@ -16,10 +15,8 @@ class Department < ApplicationRecord
def reset_data_cache
# 清除部门名称缓存
if new_record? || name_previously_changed?
Rails.cache.delete(self.class.names_data_cache_key(school_id))
end
end
def self.names_data_cache_key(school_id)
"schools/#{school_id}/department_names_data"

Loading…
Cancel
Save