> The SoftCache uses a ConcurrentHashMap, but that caching option isn't used
> in core.memoize. Are you building a custom memoizer?
>
>
WRT ConcurrentHashMap, it was an incorrect conclusion on my part. In any
case, I fail to see "thread safety" in the cache implementation, but again
I could be wrong. Or it might not be needed for 99.99% cache use cases.
Also, at that point I would like to avoid to "defcache" my own version.


So I ended up with this (this is my first LISP macro ever, so please be
gentle :-) :

(defmacro when-map-future-swap! [a k f]
  `(locking ~a
     (when (not (contains? @~a ~k))
       (swap! ~a assoc ~k nil)
       (future (swap! ~a assoc  ~k (~f ~k)))
       )
     )
  )

Which seems to do what I need:

user=> (defn f[k] (Thread/sleep 3000) k)
#'user/f
user=> (when-map-future-swap! a "arg" f)
#<core$future_call$reify__6320@a7f0cb9: :pending>
user=> a
#<Atom@71d68915: {"arg" nil}>
user=> (Thread/sleep 4000)
nil
user=> a
#<Atom@71d68915: {"arg" "arg"}>


Andy

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to