(ns cmr.common.test.cache
  (:require [clojure.test :refer :all]
            [cmr.common.cache :as c]))

(def counter (atom 0))

(defn increment-counter
  "Increments the counter atom and returns it"
  []
  (swap! counter inc))

(deftest cache-test
  (testing "cache hit, miss and reset"
    (let [cache-atom (c/create-cache)]
      (is (= 1 (c/cache-lookup cache-atom "key" increment-counter)))
      ;; look up again will not call the increment-counter function
      (is (= 1 (c/cache-lookup cache-atom "key" increment-counter)))
      (c/reset-cache cache-atom)
      (is (= 2 (c/cache-lookup cache-atom "key" increment-counter)))
      (is (= 2 (c/cache-lookup cache-atom "key" increment-counter))))))

(ns cmr.common.test.cache
  (:require [clojure.test :refer :all]
            [cmr.common.cache :as c]))

(def counter (atom 0))

(defn increment-counter
  "Increments the counter atom and returns it"
  []
  (swap! counter inc))

(deftest cache-test
  (testing "cache hit, miss and reset"
    (let [cache-atom (c/create-cache)]
      (reset! counter 0)
      (is (= 1 (c/cache-lookup cache-atom "key" increment-counter)))
      ;; look up again will not call the increment-counter function
      (is (= 1 (c/cache-lookup cache-atom "key" increment-counter)))
      (c/reset-cache cache-atom)
      (is (= 2 (c/cache-lookup cache-atom "key" increment-counter)))
      (is (= 2 (c/cache-lookup cache-atom "key" increment-counter))))))

Reset counter so the test can be run multiple times in repl.
Reset counter so the test can be run multiple times in repl.

mschmele/Common-Metadata-Repository,nasa/Common-Metadata-Repository,nasa/Common-Metadata-Repository,mschmele/Common-Metadata-Repository,nasa/Common-Metadata-Repository,mschmele/Common-Metadata-Repository,nasa/Common-Metadata-Repository,mschmele/Common-Metadata-Repository,nasa/Common-Metadata-Repository,nasa/Common-Metadata-Repository