0

I'm working on a usecase, where I need to populate cache by running a background function(to avoid latency induced by having the function run while handling the request). The function will make an API call to get the data and this data has to be stored in the cache of openresty.

I found that using ngx.timer.at function will help here, but since I'm new to nginx I'm not able to understand the complexities of using something like ngx.timer.at.

Can someone help me understand,

  1. What is the best way to run a cron function in background, which make the API call.
  2. If ngx.timer.at is the best approach, how does this work when used in the code? Like if the cron function makes use of additional libraries which were imported in the file from where ngx.timer.at is called will the function running background able to refer to the library from within the function? I'm trying to understand what happens when ngx.timer.at is called with a function and what all the variables/libraries that the cron function will have access to.
  3. Any documentation which I can refer to understand the working of nginx when ngx.time.at is used?

I tried searching for supporting documentation in openresty, but I just got lost as I'm very new to openresty and nginx.

Ashay Fernandes
  • 353
  • 4
  • 14

0 Answers0