class EduSetting < ApplicationRecord after_commit :expire_cache def cache_key self.class.cache_key(name) end def self.get(key) 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