Merge branch 'standalone_develop' of https://gitlink.org.cn/Trustie/forgeplus into standalone_develop
This commit is contained in:
commit
a7fd0a5437
|
@ -16,7 +16,8 @@
|
|||
|
||||
|
||||
class EduSetting < ApplicationRecord
|
||||
after_commit :expire_value_cache
|
||||
after_commit :expire_value_cache, on: [:create, :update]
|
||||
after_commit :clear_value_cache, on: :destroy
|
||||
|
||||
scope :by_search, -> (keyword){ where("name LIKE :keyword OR value LIKE :keyword", keyword: "%#{strip_param(keyword)}%") unless strip_param(keyword).blank? }
|
||||
|
||||
|
@ -25,9 +26,13 @@ class EduSetting < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.get(key)
|
||||
begin
|
||||
Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do
|
||||
find_by_name(key.to_s)&.value
|
||||
end
|
||||
rescue Exception => e
|
||||
find_by_name(key.to_s)&.value
|
||||
end
|
||||
end
|
||||
|
||||
def self.value_cache_key(name)
|
||||
|
@ -41,4 +46,8 @@ class EduSetting < ApplicationRecord
|
|||
def expire_value_cache
|
||||
Rails.cache.write(value_cache_key, value)
|
||||
end
|
||||
|
||||
def clear_value_cache
|
||||
Rails.cache.delete(value_cache_key)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue