Ring enhancement and patches are best posted to the "ring-clojure"
group. There's a chance they might be missed if only posted to the
Clojure group.

Regarding wrap-reload, your enhancements would put it halfway between
the current wrap-reload, and the wrap-reload-modified middleware
available as a third-party library:

https://github.com/weavejester/ring-reload-modified

I'm therefore inclined to keep wrap-reload the way it is, and leave
more sophisticated behaviour up to other middleware functions.

Incidentally, are you familiar with the "lein-ring" plugin for Leiningen?

https://github.com/weavejester/lein-ring

The lein-ring plugin provides a command for starting a development web
server. Any modifications to the source files are automatically
reloaded using the wrap-reload-modified middleware.

- James

On 5 January 2011 16:21, David Jagoe <davidja...@gmail.com> wrote:
> G'day,
>
> Ring ships with some development middleware that reloads the supplied
> namespaces every request. This is fantastic for quick iterative
> development, particularly because the JVM takes so long to start.
> However as soon as you have more than a few namespaces every request
> becomes rather slow - even if there are no source changes the
> middleware reloads all supplied namespaces. I have tweaked the ring
> reload middleware to only reload the namespaces if at least one file
> below the supplied directory has been modified:
>
>
> (defonce src-mtime (atom 0))
>
> (defn read-src-mtime [dir]
>  (reduce
>   (fn [a b]
>     (+ a (.lastModified b))) 0 (file-seq dir)))
>
> ;; Copied and modified from ring.middleware.reload
> (defn wrap-reload
>  "Wrap an app such that before a request is passed to the app, each
>  namespace identified by syms in reloadables is reloaded if any file
>  has changed below the identified source directory. Currently this
>  requires that the namespaces in question are being (re)loaded from
>  un-jarred source files, as apposed to source files in jars or
>  compiled classes."
>  [app dir reloadables]
>  (fn [req]
>    (let [new-mtime (read-src-mtime dir)]
>      (if (> new-mtime @src-mtime)
>        (do
>          (swap! src-mtime (constantly new-mtime))
>          (doseq [ns-sym reloadables]
>            (require ns-sym :reload)))))
>    (app req)))
>
> There are two ways in which I can immediately see that this could be improved:
>
> 1. Don't pass in src directory as well as namespaces. If the user just
> specifies the src directory then we can infer all of the namespaces?
> 2. Don't reload all namespaces when a file is changed - only the
> affected namespaces. I think this can become tricky.
>
> Anyway the current implementation works well for me and I thought it
> might benefit others. Any feedback welcome.
>
> Can I provide a patch or pull request for ring?
>
>
> Cheers,
> David
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to