Cache large drop-downs in Rails

31-Jul-2019 1706
Today I noticed that a couple of drop-downs in a key form were taking several seconds to load.At first I figured it's a slow query, because the drop-downs load data from the DB and there's several dozen records. But, no, queries take only a couple of ms. It's the rendering that is slow.Implementing a view cache for the drop-downs is straightforward, just have to come up with an expirable key.The two core elements that can expire the cache are dropdown elements changing, and the selected value changing.Usually with view caches it is also prudent to scope the key to the resource id or other unique piece of data.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle