On 16 November 2013 13:02, Marcin Skotniczny <[email protected]> wrote:
> Well, I made sure you can do it:). I created the grouped middleware
> functions for convenience's sake and I intend to add more.
>
Ah, interesting! That's a design I'm more comfortable with.
> Although this might not be good enough, because:
>
> 1. LessCSS files should be listed. You will usually want to compile
> only one or two of them, the rest will be @imported. SASS has convention to
> mark those files with underscore _ at the beginning of filename, but LESS
> doesn't have any solution like that, so...
> 2. If you specify files to compile, they will be precompiled and any
> compilation errors will be found immediately as the app won't start.
>
> Isn't this pretty easy to do by pushing through a request at
initialisation? It would have the added side benefit of pre-warming the
cache as well.
>
> 1. I tried separate caching layer, but it doesn't work so good. It
> gets especially complex with LessCSS - you have to watch imported files for
> changes too. Also, I want to add transformation with non-java tools.
> Integrating with those usually is based on filesystem anyway.
>
>
Why doesn't it work well? Have you tried taking advantage of the 304
not-modified header?
For instance:
(-> less-route
wrap-not-modified
wrap-compile-less
(wrap-cache (file-cache "tmp"))
In this case, the "less-route" function returns a response with a
"Last-Modified" header in the response. If the request contains a
"If-Modified-Since" header, then the wrap-not-modified middleware can
replace the normal response with a 304 not-modified response.
Then, all we have to do is have the wrap-compile-less middleware pass up
any 304 responses without touching them, and the cache can then replace the
304 response with the cached version instead.
I'm working on a ring-cache library that will handle caching in a fairly
generic fashion by taking advantage of the infrastructure HTTP already has
for handling this. The core middleware looks like:
(defn wrap-cache [handler cache]
(fn [request]
(if (not= (:request-method request) :get)
(handler request)
(let [timestamp (java.util.Date.)
cached (retrieve cache (:uri request))
request (-> request (if-modified-since (:timestamp cached)))
response (handler request)]
(if (not-modified? response)
(:response cached)
(do (store! cache (:uri request) {:response response :timestamp
timestamp})
response))))))
- James
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.