   
 (defn- get-image
   [cache-agent dir key]
+  (send-off cache-agent #(.hit %1 %2) key) 
   (or (clojure.core/get @cache-agent key)
       (do
-        (send-off cache-agent #(.hit %1 %2) key) 
         (.submit file-service
                  #(let [image (image/read-processor (key-map-to-file-name dir key))]
                     (send-off cache-agent assoc key image)))

(defn image-cache
  "Creates an image cache that uses a LRU policy to store memory-cache-size
   images in memory, and also stores all images on disk in TIFF files in the
   specified directory."
  [dir memory-cache-size]
  (ImageCache. (agent (cache/lru-cache-factory memory-cache-size {})) dir))

  (get [this key]
       "Read an image from cache.")
  (has [this key]
       "Checks if image is available in cache.")
  (memory [this]
       "Returns the current value stored in memory.")
  (different [this other]
             "Checks if the memory value is different."))

(deftype ImageCache [cache-agent dir]
  ImageCacheProtocol
    (add [_ key image] (add-image cache-agent dir key image))
    (get [_ key] (get-image cache-agent dir key))
    (has [_ key] (has-image @cache-agent dir key))
    (memory [_] @cache-agent)
    (different [this other] (memory this) (.memory other))
  clojure.lang.IRef
    (addWatch [this Object IFn] (do (.addWatch cache-agent Object IFn) this))
    (deref [_] (.deref cache-agent))
