bcgov / entity

ServiceBC Registry Team working on Legal Entities
Apache License 2.0
23 stars 59 forks source link

Caching service account access tokens #16527

Closed seeker25 closed 1 year ago

seeker25 commented 1 year ago

We should build a generalized solution that can cache service account access tokens.

So we're not requesting a new token each time we have a request coming in.

Ideally this would work outside the flask context if possible. That way we could use these in jobs and queue services etc.

It's also possible to set access token timeouts higher than 2 minutes directly for certain clients.

image

It might be possible to set it up to 20m and cache all of the tokens.

Also see: https://github.com/bcgov/entity/issues/15233

See #registries-sso-migration for the calls from May 24th.

pwei1018 commented 1 year ago

@bolyachevets What do you think?

bolyachevets commented 1 year ago

@bolyachevets What do you think?

it is a good idea. something tells me we will be asked to do reduce the number of calls in the near future.

thorwolpert commented 1 year ago

Pallets (which maintains flask) has a cache library. We already use it to do simple caching, and it can memoize easily enough as well. Does exactly what you're looking for. https://github.com/pallets-eco/cachelib