LG-7814: Cache USPS auth token as class member#7147
Conversation
aduth
left a comment
There was a problem hiding this comment.
It might be a good idea to test this against live APIs before it's deployed to production, but implementation LGTM 👍
Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov>
Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov>
Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov>
|
@aduth will definitely test it out in a lower environment, I'm thinking I'll go ahead and merge it and do some testing in dev. I added it as an A/C to the ticket |
| @@ -1,5 +1,6 @@ | |||
| module UspsInPersonProofing | |||
| class Proofer | |||
| mattr_reader :token, :token_expires_at | |||
There was a problem hiding this comment.
Would it be safe to use Rails.cache for this to share across instances?
There was a problem hiding this comment.
I think so but is there a benefit to that over a class member?
There was a problem hiding this comment.
Class members can be hard to test/reason about sometimes mattr_reader vs cattr_reader and then have to be reset explicitly in tests, but Rails.cache has easy methods for clearing it.
Also with like 10+ boxes, with probably 4+ processes each, each one will have to cache separately, so having a shared cache (we use Redis to back our Rails.cache) might save extra requests to the API overall
There was a problem hiding this comment.
Oh cool it's shared across processes and instances? Yeah I'll go ahead and switch it to Rails.cache
There was a problem hiding this comment.
in prod, yes!, locally it might just be in-memory
There was a problem hiding this comment.
Oops, seeing this conversation after PRing an identical approach. @sheldon-b will this be updated in a future PR? maybe we can pair on this and this one ...
There was a problem hiding this comment.
Yeah the original ticket is already marked Done and shipped to prod. I've created LG-7918 to move the caching to the rails cache
Happy to pair! I'll bring LG-7918 to refinement today
🎫 Ticket
LG-7814
🛠 Summary of changes