Permalink
Browse files

added caching to response format parsing

  • Loading branch information...
1 parent 7d094d4 commit e31944d49646adc225664628b9061ce716b495d9 @ngrunwald committed Apr 23, 2012
Showing with 5 additions and 1 deletion.
  1. +1 −0 project.clj
  2. +4 −1 src/ring/middleware/format_response.clj
View
@@ -3,6 +3,7 @@
responses in various formats. See
https://github.com/ngrunwald/ring-middleware-format"
:dependencies [[org.clojure/clojure "1.2.1"]
+ [org.clojure/core.memoize "0.5.1"]
[ring/ring-core "1.0.2"]
[cheshire "4.0.0"]
[clj-yaml "0.3.1"]])
@@ -4,6 +4,7 @@
[clojure.java.io :as io]
[clj-yaml.core :as yaml]
[clojure.string :as s])
+ (:use [clojure.core.memoize :only [memo-lu]])
(:import [java.io File InputStream BufferedInputStream]))
(defn serializable?
@@ -35,7 +36,7 @@
:else -1))
headers))
-(defn parse-accept-header
+(defn- parse-accept-header*
"Parse Accept headers into a sorted sequence of maps.
\"application/json;level=1;q=0.4\"
=> ({:type \"application\" :sub-type \"json\"
@@ -65,6 +66,8 @@
(sort-by-check :sub-type "*")
(sort-by :q >)))
+(def parse-accept-header (memo-lu parse-accept-header* 100))
+
(defn preferred-encoder
"Return the encoder that encodes to the most preferred type.
If the Accept header of the request is a string, assume it is

0 comments on commit e31944d

Please sign in to comment.