How to Properly Use caching in Rails 5.2.3?

How to use Action caching?
How to expire the action caching in the model?
My controller app/controllers/normal_reservation_controller.rb

class NormalReservationsController < ApplicationController
    cache_sweeper: normal_reservation_sweeper
    caches_action :index
      def index
        #code
      end
end

My Sweeper app/sweepers/normal_reservation_sweeper.rb

class NormalReservationSweeper < ActionController::Caching::Sweeper
observe NormalReservation
def after_create(reservation)
expire_index_reservation
end

def after_destroy(reservation)
expire_index_reservation
end

def after_update(reservation)
expire_index_reservation
end

private

def expire_index(reservation)
expire_action(:controller => ‘normal_reservations’, :action => ‘index’)
end
end

but I am getting an error like this


Thanks!!

Hey @giridharan, unfortunately you have to add cache sweepers in the controller, not in the model.