parent
09d8e6e5da
commit
34dc1032d8
@ -1,5 +1,25 @@
|
||||
class EduSetting < ApplicationRecord
|
||||
after_commit :expire_cache
|
||||
|
||||
def cache_key
|
||||
self.class.cache_key(name)
|
||||
end
|
||||
|
||||
def self.get(key)
|
||||
find_by_name(key.to_s)&.value
|
||||
Rails.cache.fetch(cache_key(key), expires_in: 1.days) do
|
||||
find_by_name(key.to_s)&.value
|
||||
end
|
||||
end
|
||||
|
||||
def self.cache_key(name)
|
||||
raise ArgumentError if name.blank?
|
||||
|
||||
"educoder/edu-settings/#{name.to_s}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expire_cache
|
||||
Rails.cache.clear(cache_key)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in new issue