     {"status" "OK"
      "message" "PROCESSING"}))
 
+(defn- get-report-by-id [rid]
+  (let [found (filter #(= rid (:id %)) (keys @cache))]
+    (if (empty? found)
+      nil
+      (@cache (nth found 0)))))
+
 (defn generate-report [params]
   "Returns the cached report for the given parameters, or schedules the report for execution"
-  (if-let [f (@cache (report-id params))]
+  (if-let [f (get-report-by-id (report-id params))]
    {"status" "OK"
     "file" f}
    (schedule-job params)))

         report (exp/doexport exportType baseURL sid opts)
         path (s/join "/" (take-last 2 (s/split (.getAbsolutePath report) #"/")))]
    (dosync
      (alter cache conj {reportId path}))
    (qs/delete-job (j/key reportId))))




(defn invalidate-cache [params]
  "Invalidates (remove) a given file from the cache"
  (let [baseURL (params "baseURL")]
    (doseq [sid (params "surveyIds")]
    (dosync
      (doseq [k (keys @cache) :when (and (= (k :baseURL) baseURL) (= (str sid) (k :surveyId)))]
      (alter cache dissoc k))))
    {"status" "OK"}))
