From 3f837dbda5c742c104c5e9330852948ed7197ff5 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:48:01 +0800 Subject: [PATCH] modify edusetting cache key method Avoid duplication --- app/models/edu_setting.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index e6e4d900e..4b39dea81 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -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