Skip to content

Commit ddf85a6

Browse files
committed
Merge branch 'bug-fix'
2 parents d3792f2 + de149d5 commit ddf85a6

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject com.appsflyer/cloffeine "0.1.5"
1+
(defproject com.appsflyer/cloffeine "0.1.6"
22
:description "A warpper over https://github.com/ben-manes/caffeine"
33
:url "https://github.com/AppsFlyer/cloffeine"
44
:license {:name "Eclipse Public License"

src/cloffeine/async_loading_cache.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"Create an AsyncLoadingCache. See `cloffeine.common/builder` for settings.
1010
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.)
1111
Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads."
12-
(^AsyncLoadingCache [^CacheLoader cl]
13-
(make-cache cl {}))
14-
(^AsyncLoadingCache [^CacheLoader cl settings]
12+
(^AsyncLoadingCache [cache-loader]
13+
(make-cache cache-loader {}))
14+
(^AsyncLoadingCache [cache-loader settings]
1515
(let [bldr (common/make-builder settings)]
16-
(.buildAsync bldr cl))))
16+
(.buildAsync bldr cache-loader))))
1717

1818
(defn make-cache-async-loader
1919
"Create a CacheLoader"

test/cloffeine/core_test.clj

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
(deftest loading-exceptions
7373
(let [loads (atom 0)
7474
throw? (atom false)
75+
load-nil? (atom false)
7576
cl (common/reify-cache-loader (fn [k]
76-
(if @throw?
77-
(throw (ex-info "fail" {}))
78-
(do
79-
(swap! loads inc)
80-
(name k)))))
77+
(cond
78+
@throw? (throw (ex-info "fail" {}))
79+
@load-nil? nil
80+
:else (do
81+
(swap! loads inc)
82+
(name k)))))
8183
ticker (FakeTicker.)
8284
lcache (loading-cache/make-cache cl {:refreshAfterWrite 10
8385
:timeUnit :s
@@ -101,7 +103,12 @@
101103
(is (= "key" (loading-cache/get lcache :key)))
102104
(is (= 1 @loads))
103105
(is (= "key" (loading-cache/get lcache :key)))
104-
(is (= 1 @loads)))))
106+
(is (= 1 @loads)))
107+
(testing "loading a missing key but loader returns nil. nil returns, but mapping is not changed"
108+
(reset! throw? false)
109+
(reset! load-nil? true)
110+
(is (nil? (loading-cache/get lcache :not-there)))
111+
(is (= [:key] (keys (.asMap lcache)))))))
105112

106113
(deftest get-if-present
107114
(let [cache (cache/make-cache)]

0 commit comments

Comments
 (0)