class Comment < ApplicationRecord
belongs_to :post, touch: true
belongs_to :author, class_name: "User"
validates :body, presence: true, length: { maximum: 10_000 }
module CollectionCacheKey
extend ActiveSupport::Concern
def cache_key_for(scope)
relation = scope.respond_to?(:all) ? scope.all : scope
model = relation.klass
class CacheNamespace
attr_reader :name
def initialize(name, store: Rails.cache)
@name = name.to_s
@store = store