               response)))))
     (do
       (log/info "Not logging modifying requests.")
-      (fn [request]
-        (next-handler request)))))
+      next-handler)))
 
 (def audit-logs-file-format)
+
+(def default-audit-flush-millis (* 5 60 1000))
 
 (defn store-audit-logs!
   "Stores the audit logs in an S3 bucket."
   [audit-logs bucket]
   (let [previous-logs (empty-logs audit-logs)]
-    (try
-      (let [file-content (string/join "\n" (map json/write-str previous-logs))
-            file-stream (-> file-content (.getBytes "UTF-8") (ByteArrayInputStream.))
-            content-length (count file-content)
-            file-name (t/now)]
-        (s3/put-object :bucket-name bucket
-                       :key file-name
-                       :input-stream file-stream
-                       :metadata {:content-length content-length}))
-      (catch Throwable t
-        (add-logs audit-logs previous-logs)
-        (log/warn "Could not store audit logs because of %s." (str t))))))
+    (when (seq previous-logs)
+      (try
+        (let [file-content (string/join "\n" (map json/write-str previous-logs))
+              file-stream (-> file-content (.getBytes "UTF-8") (ByteArrayInputStream.))
+              content-length (count file-content)
+              file-name (str (t/now))]
+          (s3/put-object :bucket-name bucket
+                         :key file-name
+                         :input-stream file-stream
+                         :metadata {:content-length content-length}))
+        (catch Throwable t
+          (add-logs audit-logs previous-logs)
+          (log/warn "Could not store audit logs because of %s." (str t)))))))
+
+(defn schedule-audit-log-flusher [bucket audit-logs configuration]
+  (when bucket
+    (let [flush-interval (or (:audit-flush-millis configuration) default-audit-flush-millis)
+          pool (at/mk-pool :cpu-count 1)]
+      (at/every flush-interval #(store-audit-logs! audit-logs bucket) pool :initial-delay flush-interval)
+      pool)))
+
+(defn stop-audit-log-flusher [bucket audit-logs pool]
+  (when bucket
+    (dosync
+      (at/stop-and-reset-pool! pool :strategy :kill)
+      (store-audit-logs! audit-logs bucket))))
 
 (defn start-component
   "Starts the http component."

      (log/info "Stopping HTTP daemon.")
      (when-not (:no-listen? (:configuration component))
        (.stop (:httpd component))
        (.stop (:hystrix-httpd component)))
      (merge component {:httpd         nil
                        :hystrix-httpd nil
                        :handler       nil}))))

(defmacro def-http-component
  "Creates an http component with your name and all your given dependencies. Those dependencies will also be available

      (log/info "Logging all successful, modifying requests.")
      (fn [request]
        (let [{:keys [status] :as response} (next-handler request)]
          (when (and (>= status 200)
                     (< status 300)
                     (is-modifying? request))
            (let [audit-log (-> request
                                (assoc :logged-on (t/now))
                                (dissoc :swagger)
