modify edusetting cache key method Avoid duplication

dev_course
p31729568 6 years ago
parent 34dc1032d8
commit 3f837dbda5

@ -1,17 +1,17 @@
class EduSetting < ApplicationRecord
after_commit :expire_cache
after_commit :expire_value_cache
def cache_key
self.class.cache_key(name)
def value_cache_key
self.class.value_cache_key(name)
end
def self.get(key)
Rails.cache.fetch(cache_key(key), expires_in: 1.days) do
Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do
find_by_name(key.to_s)&.value
end
end
def self.cache_key(name)
def self.value_cache_key(name)
raise ArgumentError if name.blank?
"educoder/edu-settings/#{name.to_s}"
@ -19,7 +19,7 @@ class EduSetting < ApplicationRecord
private
def expire_cache
Rails.cache.clear(cache_key)
def expire_value_cache
Rails.cache.clear(value_cache_key)
end
end

Loading…
Cancel
Save