# frozen_string_literal: true class CacherObserver < ActiveRecord::Observer observe Post, Question, Testimonial, XmlImport, Settings, Structure, SiteActivity, Feature, ExtraFeature, ContentStorage, PopularLanguage def after_create(_record) self.class.clear_cache end def after_update(_record) self.class.clear_cache end def after_destroy(_record) self.class.clear_cache end # Clear all avaiable cache class << self def clear_cache Rails.cache.clear FileUtils.rm_rf Dir[Rails.root.join('tmp', 'file_cache', 'pages', '**/*').to_s] FileUtils.rm_rf Dir[Rails.root.join('public', 'cache', '**/*').to_s] end end end