Skip to content

5. Introducing token caching

Compare
Choose a tag to compare
@mderriey mderriey released this 20 Feb 03:03
c3df01f

Something we need to be aware of when we consume Azure Identity ourselves (i.e. outside of the Azure SDK), is that many concerns are not taken care of for us, like token caching.

In our previous implementation, we were requesting a token (implying a network request) every time we load the page, which is far from ideal.

To remediate this, we take the following steps:

  1. We create a new abstraction called IAzureSqlTokenProvider representing the process of acquiring a token for Azure SQL.
  2. We create a base implementation that leverages Azure Identity, which is identical to what we had before in SqlConnectionFactory.
  3. We introduce caching via the decorator pattern; to avoid network requests, we cache them in memory.
  4. Finally, we use the excellent Scrutor NuGet package that adds support for decorators to the built-in dependency injection container.

Diff from previous tag: 4.using-sql-with-aad-auth...5.introduce-token-caching