Open AndyKriger opened 7 years ago
defonce might do the trick
On Mon, Jun 26, 2017, 10:57 AM Andy Kriger notifications@github.com wrote:
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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/weavejester/lein-ring/issues/188, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMv1Ry9LwZJ1Pbyn4LNEz8RIn40dWkpks5sH_EcgaJpZM4OFpi6 .
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.