Let's say I want an interceptor that will check a cache for some value args
that should already be in the context map. if it exists, the val for that args
key should be the response. Otherwise, continue the interceptor chain, and when there is a response cache it.
(def cache (atom {}))
{:enter (fn [{:keys [args] :as ctx}]
(if (contains? @cache args)
(chain/terminate ctx)
ctx))
:leave (fn [{:keys [response args] :as ctx}]
(if response
(do (swap! cache assoc args response) ctx)
(assoc ctx :response (get @cache))))}
Is this the standard way this should be implemented? It would feel more natural to me to assoc the cached response if it exists in the enter function (but then i'd be updating the cache every time even when a value already exists for it). Are there any obvious better ways to handle this?