gocaching

How to avoid or delay extra work on cache miss


Is there a suggested pattern to mitigate known cache misses? I have a map being populated with the response from an API call over the network. There should be almost no cache misses as this data rarely changes. On each cache miss I make an API call. How can I (in Golang or in general) avoid spamming the API endpoint? (this happens when data is missing and will never be there or won't be there for a long time, i.e. always missing the cache). Would there need to be some sort of delayed calls for previous misses (like back off or ...)?


Solution

  • I ended up using a simple timeout as @Burak suggested. This was simpler than circuit breaker and worked just fine for this use case. It can avoid spamming when data that is a minute old in not a concern.