On 7 December 2014 at 05:13, Andy L <core.as...@gmail.com> wrote: > > > >> 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. >
Most of the cache implementations in core.cache have no side-effects. They simply return a new cache rather than overwriting the old one. The memoize library places the cache in an atom, so it's guaranteed to change atomically. > 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))) > ) > ) > ) > You could write this as a function. There's nothing in there that requires a macro. (defn 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)))))) But I'd personally just use a delay rather than "locking" for this purpose. - James -- 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.