Skip to content

Commit f9cd940

Browse files
committed
CMR-11116: pr nitpicks
1 parent 81088e0 commit f9cd940

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

common-lib/src/cmr/common/cache/fallback_cache.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
(cache/set-value backup-cache key value)
7878
(cache/set-value primary-cache key value))
7979

80+
(evict
81+
[_this key]
82+
(cache/evict primary-cache key)
83+
(cache/evict backup-cache key))
84+
8085
(cache-size
8186
[_]
8287
(+ (cache/cache-size primary-cache)

common-lib/src/cmr/common/cache/single_thread_lookup_cache.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
(when (cache/simple-cache? delegate-cache)
131131
(cache/set-value delegate-cache cache-key value)))
132132

133+
(evict
134+
[_this cache-key]
135+
(when (cache/simple-cache? delegate-cache)
136+
(cache/evict delegate-cache cache-key)))
137+
133138
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134139
life/Lifecycle
135140
(start

mock-echo-app/src/cmr/mock_echo/api/urs.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@
6666
(let [expires-in 1600
6767
validation-info (get @launchpad-token-validations token)]
6868
(if validation-info
69-
(let [elapsed-seconds (t/in-seconds (t/interval (:first-validated-at validation-info) (time-keeper/now)))]
70-
(if (>= elapsed-seconds expires-in)
69+
(let [stored-expires-in (:expires-in validation-info)
70+
elapsed-seconds (t/in-seconds (t/interval (:first-validated-at validation-info) (time-keeper/now)))]
71+
(if (>= elapsed-seconds stored-expires-in)
7172
{:status 401 :body {:error (format "Launchpad token (partially redacted) [%s] has expired."
7273
(common-util/scrub-token token))}}
73-
{:status 200 :body {:uid "user1" :lp_token_expires_in (- expires-in elapsed-seconds)}}))
74+
{:status 200 :body {:uid "user1" :lp_token_expires_in (- stored-expires-in elapsed-seconds)}}))
7475
(do
7576
(swap! launchpad-token-validations assoc token {:first-validated-at (time-keeper/now) :expires-in expires-in})
7677
{:status 200 :body {:uid "user1" :lp_token_expires_in expires-in}})))

redis-utils-lib/src/cmr/redis_utils/redis_cache.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
(wcar* s-key false primary-connection (carmine/set s-key {:value value})
8686
(when ttl (carmine/expire s-key ttl)))))
8787

88+
(evict
89+
[_this key]
90+
(let [s-key (serialize key)]
91+
(wcar* key false primary-connection (carmine/del s-key))))
92+
8893
(cache-size
8994
[_]
9095
(reduce #(+ %1 (if-let [size (wcar* (serialize %2) true read-connection (carmine/memory-usage (serialize %2)))]

system-int-test/test/cmr/system_int_test/misc/launchpad_user_cache.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(deftest launchpad-user-cache-test
2424
(testing "launchpad cache initial value"
2525
(let [launchpad-token (echo-util/login-with-launchpad-token (system/context) "user1")
26-
token-key (keyword (DigestUtils/sha256Hex launchpad-token))]
26+
token-key (DigestUtils/sha256Hex launchpad-token)]
2727
(is (empty? (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token)))
2828
(let [concept (data-umm-c/collection-concept {})
2929
{:keys [concept-id revision-id]} (ingest/ingest-concept concept {:token launchpad-token})]
@@ -35,7 +35,7 @@
3535
(is (= (:uid (cache-util/get-cache-value
3636
(url/ingest-read-caches-url)
3737
"launchpad-user"
38-
(name token-key)
38+
token-key
3939
transmit-config/mock-echo-system-token
4040
200))
4141
"user1"))
@@ -52,7 +52,7 @@
5252
(let [expiration-time (:expiration-time (cache-util/get-cache-value
5353
(url/ingest-read-caches-url)
5454
"launchpad-user"
55-
(name token-key)
55+
token-key
5656
transmit-config/mock-echo-system-token
5757
200))]
5858
(ingest/ingest-concept concept {:token launchpad-token})
@@ -61,7 +61,7 @@
6161
(is (= expiration-time (:expiration-time (cache-util/get-cache-value
6262
(url/ingest-read-caches-url)
6363
"launchpad-user"
64-
(name token-key)
64+
token-key
6565
transmit-config/mock-echo-system-token
6666
200))))
6767
(testing "token cache value expires"
@@ -100,7 +100,7 @@
100100
(deftest non-transient-errors-are-cached-test
101101
(testing "Non-transient errors are cached for 5 minutes"
102102
(let [token "ABC-INV-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
103-
token-key (keyword (DigestUtils/sha256Hex token))]
103+
token-key (DigestUtils/sha256Hex token)]
104104
(let [resp (ingest/ingest-concept (data-umm-c/collection-concept {}) {:token token})]
105105
(is (= 401 (:status resp))))
106106

@@ -109,7 +109,7 @@
109109
(let [cached-value (cache-util/get-cache-value
110110
(url/ingest-read-caches-url)
111111
"launchpad-user"
112-
(name token-key)
112+
token-key
113113
transmit-config/mock-echo-system-token
114114
200)]
115115
(is (false? (:valid cached-value)))

transmit-lib/src/cmr/transmit/launchpad_user_cache.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
:error-type error-type
5656
:expiration-time (t/plus (time-keeper/now) (t/minutes (transmit-config/invalid-token-timeout)))})))))]
5757
(if-let [cache (cache/context->cache context launchpad-user-cache-key)]
58-
(let [cache-key (keyword (DigestUtils/sha256Hex token))
58+
(let [cache-key (DigestUtils/sha256Hex token)
5959
token-info (cache/get-value cache cache-key get-launchpad-user-fn)]
6060
(if (t/before? (:expiration-time token-info) (time-keeper/now))
6161
;; Cache entry expired (after 5 min for errors, or token lifetime for valid tokens)

0 commit comments

Comments
 (0)