Skip to content

Commit

Permalink
Fixes [IMMUTANT-304]
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrossley3 committed Jul 9, 2013
1 parent 6905335 commit 2adfd1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modules/cache/src/main/clojure/immutant/cache/core.clj
Expand Up @@ -90,10 +90,13 @@
locking (throw (IllegalArgumentException. (str "Invalid locking mode: " locking))))
(.build builder)))

(defn default-mode []
(defn default-mode [opts]
(if (and service (.isClustered service))
:distributed
:local))
(merge {:mode :distributed} opts)
(do
(if-not (= :local (:mode opts :local))
(log/warn "Cache replication only supported when clustered"))
(assoc opts :mode :local))))

(defn get-cache
"Returns the named cache if it exists, otherwise nil"
Expand All @@ -105,7 +108,7 @@
"Defaults to :distributed with :sync=true for a clustered cache, otherwise :local"
[name opts]
(let [default (.getDefaultCacheConfiguration @manager)
settings (merge {:template default, :mode (default-mode), :sync true} opts)
settings (merge {:template default, :sync true} (default-mode opts))
config (build-config settings)]
(log/info (str "Configuring cache [" name "] as "
(select-keys settings [:mode :sync :locking :persist :max-entries :eviction])))
Expand Down
3 changes: 3 additions & 0 deletions modules/cache/src/test/clojure/test/immutant/cache.clj
Expand Up @@ -226,3 +226,6 @@
(let [seed {:a 1, :b {:c 42}}
c (create "seedy" :seed seed)]
(is (= seed (into {} (seq c))))))

(deftest default-to-local "should not raise exception"
(create "remote" :mode :replicated))

0 comments on commit 2adfd1f

Please sign in to comment.