mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-14 22:51:26 -05:00
For every email or text message we send we have to work out which provider to send it with. Every time we do this we go and load the list of providers from the database. For emails, the result will always be the same. For text messages the result is randomly chosen to balance the load between the providers. For international text messages the result is always the same (we only have one international text message provider). This commit adds an in-memory cache with a 2 second TTL so that we’re not fetching the providers from the database every time, which should speed things up a bit. This does mean that, for text messages, the random choice will ‘stick’ for two seconds on each instance, before being re-chosen. I think this is OK because it will even out to the same distribution over time. I really don’t like having to clear the cache in the tests, so would welcome suggestions on a better way of doing this…