Skip to content

Commit

Permalink
Merge branch 'bug-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
barkanido committed Sep 18, 2020
2 parents d3792f2 + de149d5 commit ddf85a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/cloffeine/async_loading_cache.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 13 additions & 6 deletions test/cloffeine/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
Expand Down

0 comments on commit ddf85a6

Please sign in to comment.