-
Notifications
You must be signed in to change notification settings - Fork 99
Description
I have a small application that loads a file of data for caching in an atom. Right now the way that happens is (def cache (atom {}))
and (defn init [] ;; reset! the atom from a file)
. I do it that way so that the file reading only happens when the server is run.
I notice that when I change the Clojure file that is my web app, the atom is reset to it's initial value, rather than the value it is set to by the init function. This makes sense since init is only called on server startup.
Is there a hook that can be called when the file is reloaded that could be used to re-initialize the cache?
Alternatively, is there a more recommended way to do this kind of global caching? While I understand that global state usually is a bad idea, in this case, it makes a lot of sense because this is a small amount of static data that only needs to be loaded once by the server and can be kept in memory for responses to requests.