Fork me on GitHub
#beginners
<
2016-08-21
>
seancorfield02:08:02

Since the def would be evaluated whenever the namespace was loaded, I’d be very wary of that approach… If you don’t want to have a genuine "application start" function that is called at startup, you could use delay to ensure that the file is only read when you need the contents of if:

(def edn-contents (delay (slurp ( "path/to/file.edn"))))

(defn handler [req]
  {:status 200
   :body @edn-contents})
This still ensures the file is only read once, but now you can load the namespace without actually reading the file.

seancorfield02:08:53

The problem with a raw def is that if you AOT compile your code (to produce an uberjar etc), the file would be read during compilation.

olegakbarov10:08:14

thank you for detailed explanation!