Fibers + Kemal question

I have a Crystal 0.34.0 / Kemal 0.26.1 site running on Heroku. I recently added caching of data and views using a Redis backend. This works great, though it’s only activated as-needed.

I was wondering if I should pre-load the cahe, using fibers, whenever Kemal starts up, since Heroku does a daily restart of the dyno?

Is this a good idea, or am I missing any fiber-related “gotchas”?

I’m assuming Kemal stays running all day until Heroku does a restart. So, my cache preloading would occur in the top of my main Kemal .cr file. Unless Kemal executes that per every request. In that case I’d need access to some Kemal-related block which only executes once upon initial startup.

1 Like

This seems like a good idea to me. I have done some cache preloading in apps but have done it through intentionally hitting the API. This was because of the specific design of the application but I am curious to hear what other people have to say.

Yeah, in Rails I always preloaded my cache items. I had a specific script in config/initializers/preload_cache.rb. Rails only ran initializers once upon startup.