0

I need to perform a two level caching mechanism on a food menu refresh application. I have to use Memcache and Redis for caching.

First need to check the menu is present in the memcache, if it is not or fail to fetch, need to move to redis caching and check the menu is present on not, if it not or fails due to some redis issue fetch the menu item from the DB.

pos_items = Rails.cache
              .fetch("pos_menu_items_for_location_#{@location_id}", expires_in: 90.days) do
              pos_items = RedisCache::PosMenu.fetch(location_id: @location_id) do
                            pos_items = PosMenuReader.new(location_id: @location_id).call
                            RedisCache::PosMenu.update(location_id: @location_id, menu: pos_items) unless pos_items == "working"
                            if pos_items == "working" 
                              wait_for_worker_to_finish = true
                            else %> 
                              <% Rails.logger.info("DEBUG::PosMenu::#{pos_menu_key} Fetched from db.") %>
                              <% pos_items %>
                          <% end
                          end
          end %>

0 Answers0