I came up with a solution for rake routes to run every 8 seconds. This is a simple file cache that runs bundle exec rake routes , saves the output in a file under tmp. The file name is the hash of md5 config/routes.rb , so if you make changes and change it, it will use the old file in the cache.
I put the following bash functions in an executable, which I call fastroutes :
if [ ! -f config/routes.rb ]; then echo "Not in root of rails app" exit 1 fi cached_routes_filename="tmp/cached_routes_$(md5 -q config/routes.rb).txt" function cache_routes { bundle exec rake routes > $cached_routes_filename } function clear_cache { for old_file in $(ls tmp/cache_routes*.txt); do rm $old_file done } function show_cache { cat $cached_routes_filename } function show_current_filename { echo $cached_routes_filename } function main { if [ ! -f $cached_routes_filename ]; then cache_routes fi show_cache } if [[ "$1" == "-f" ]] then show_current_filename elif [[ "$1" == "-r" ]] then rm $cached_routes_filename cache_routes else main fi
Here is the github link .
This way, you only need to create routes once, and then fastroutes will use the cached values.
source share