Search code examples
apiazureazure-functionsazure-caching

Azure functions output caching


I am creating Azure functions to return data from a database (Azure AS). I will be returning same data for all the requests, so caching the output seems like a good idea as the data changes only once a day

What are my options here?


Solution

  • Options listed from most simple to most complex:

    1. One option is to use static variables - but since the process can get recycled very quickly (assume every few minutes), that may not help much.

    2. Cache via storage (Blob / Table). Your function can first try to read from the table, if missing, it can then read from the database and save back to the table. You could have a second timer function that deletes old cache entries every N hours.
      I'd recommend starting here.

    3. Azure Functions can still run arbitrary code, you could call out to any other caching service (ie, Redis) and use the same patterns that you'd use in ASP.Net.