through method should always have cache as first argument to make it more friendly for swap!

Description

Given that "through" returns a new cache (like the other methods), it is quite likely that people will store the cache in an atom. Currently, code using through looks like this:

(defn load-secondary-index-segment [[filename offset length :as segment]]
(swap! segment-cache #(cache/through fetch-secondary-index-segment % segment))
(cache/lookup @segment-cache segment))

If the cache argument were always first, it would work nicely with swap, ->, etc, be more consistent with conj, assoc, etc, and you'd have this instead:

(defn load-secondary-index-segment [[filename offset length :as segment]]
(swap! segment-cache cache/through fetch-secondary-index-segment segment)
(cache/lookup @segment-cache segment))

Environment

None

Activity

Show:
Sean Corfield
March 2, 2018, 7:35 AM

Release 0.7.0

Sean Corfield
March 1, 2018, 6:54 AM

Will be in the next release.

Sean Corfield
March 1, 2018, 6:51 AM

I'm adding a new function through-cache for this.

import
January 6, 2016, 12:37 AM

I signed up to Jira to report this very issue, only to find it already reported. I've had to use some particularly ugly code to work around this API decision. Example, I have a cache atom "user-cache" that I need to either hit or add to based on an action: (swap! user-cache #(cache/through (constantly value) % key))

I'd like to go further than swapping the order of arguments though. Rather than do that (and break backwards compatibility), how about a new function that takes a value instead of a value-fn? That way the (constantly value) can just become value instead.

Completed

Assignee

Sean Corfield

Reporter

import

Labels

None

Approval

None

Patch

None

Priority

Minor