Member-only story

Azure Functions and Caching: Sometimes its a tricky situation

Raunak Narooka
4 min readJul 14, 2020

--

Caching is such a wonderful concept. It’s an easy to believe, practical and an efficient solution to many time constraint problems. It makes things very efficient , and its always feel good to explain the concept to your stakeholders.

But it does come with its own set of problems.When should we refresh the cache? How to handle logic if things are not in cache? Caching frameworks try to address this solutions, but there is never a perfect solution. There is always a small risk that you might get old values, its a tricky situation. You solve the problem, and the problem itself gives a new messy one.

Fortunately, this tricky situation can be mitigated if you understand the business requirements well and then tweak the Caching framework to suit you. But sometimes the infrastructure needs to be considered. And especially if you are working on Cloud PaaS.

I would limit my discussion to the awesome Azure Function infrastructure and how caching works with it. It comes in 3 flavors:

  • Consumption Plan
  • Elastic Premium Plan (EP1, EP2…)
  • Functions in an App Service Plan

If you are using Azure Functions and Caching, the easiest way to start with is to use a static dictionary.

For example: You have a business requirement, where you need to do a daily batch every night, and you need to get the StoreNumbers, TaxRates to process this daily batch.

These values are just look up values which will change occasionally and the change if it happens, will happen by a business analyst in day time.

You might do something like this in C#:

static Dictionary<string, string> dictionaryOfTaxRates = new Dictionary<string, string> { };
if (dictionaryOfTaxRates.Count == 0)
{
//Get the values if nothing is in dictionary
}

The daily batch runs every day and there is no issue. Simple and neat solution, isn’t it? Then the values change. And…

--

--

Raunak Narooka
Raunak Narooka

Written by Raunak Narooka

Avid lover of new technologies, believes in humanity, mostly writes about his experience in Azure https://www.linkedin.com/in/raunak-narooka/

Responses (1)

Write a response