diff --git a/project.clj b/project.clj index db56b7c..10d2d97 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.appsflyer/cloffeine "0.1.5" +(defproject com.appsflyer/cloffeine "0.1.6" :description "A warpper over https://github.com/ben-manes/caffeine" :url "https://github.com/AppsFlyer/cloffeine" :license {:name "Eclipse Public License" diff --git a/src/cloffeine/async_loading_cache.clj b/src/cloffeine/async_loading_cache.clj index e5a627c..68f2008 100644 --- a/src/cloffeine/async_loading_cache.clj +++ b/src/cloffeine/async_loading_cache.clj @@ -9,11 +9,11 @@ "Create an AsyncLoadingCache. See `cloffeine.common/builder` for settings. A semi-persistent mapping from keys to values. Values are automatically loaded by the cache asynchronously, and are stored in the cache until either evicted or manually invalidated.) Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads." - (^AsyncLoadingCache [^CacheLoader cl] - (make-cache cl {})) - (^AsyncLoadingCache [^CacheLoader cl settings] + (^AsyncLoadingCache [cache-loader] + (make-cache cache-loader {})) + (^AsyncLoadingCache [cache-loader settings] (let [bldr (common/make-builder settings)] - (.buildAsync bldr cl)))) + (.buildAsync bldr cache-loader)))) (defn make-cache-async-loader "Create a CacheLoader" diff --git a/test/cloffeine/core_test.clj b/test/cloffeine/core_test.clj index 894b42d..c09e178 100644 --- a/test/cloffeine/core_test.clj +++ b/test/cloffeine/core_test.clj @@ -72,12 +72,14 @@ (deftest loading-exceptions (let [loads (atom 0) throw? (atom false) + load-nil? (atom false) cl (common/reify-cache-loader (fn [k] - (if @throw? - (throw (ex-info "fail" {})) - (do - (swap! loads inc) - (name k))))) + (cond + @throw? (throw (ex-info "fail" {})) + @load-nil? nil + :else (do + (swap! loads inc) + (name k))))) ticker (FakeTicker.) lcache (loading-cache/make-cache cl {:refreshAfterWrite 10 :timeUnit :s @@ -101,7 +103,12 @@ (is (= "key" (loading-cache/get lcache :key))) (is (= 1 @loads)) (is (= "key" (loading-cache/get lcache :key))) - (is (= 1 @loads))))) + (is (= 1 @loads))) + (testing "loading a missing key but loader returns nil. nil returns, but mapping is not changed" + (reset! throw? false) + (reset! load-nil? true) + (is (nil? (loading-cache/get lcache :not-there))) + (is (= [:key] (keys (.asMap lcache))))))) (deftest get-if-present (let [cache (cache/make-cache)]