0

I'm sure this might be a basic task but I really don't know how to set a minimum time threshold to Alamofire to avoid repeating requests too often but keeping updating data if a minimum time has passed. I know this is just a cache but it seems cache times are always defined by the server response 'Cache-Control' header and it's not under my control.

Of course, I can track the time manually but I wonder if there's a built-in option to do it.

rmvz3
  • 1,133
  • 2
  • 16
  • 27

1 Answers1

0

There a few ways you can implement this. For example:

1.
One way is to implement this at your backend using middleware limiting incoming HTTP requests.
2.
Or you write your own logic queue which will count all requests made already.
When the limit is reached don't make an request again.

There is not an built in option for that so you have to implement the logic yourself.

BilalReffas
  • 8,132
  • 4
  • 50
  • 71
  • I'll take the last sentence as the right answer since nobody seems to add more info on this. I'm quite surprised to be honest. It seems something that should be essential in any cache system IMHO. – rmvz3 Mar 11 '18 at 19:33
  • @rmvz3, you don't need to mark an answer accepted if you are not happy with it or it does not solves your problem; if you mark an answer as _correct_ that prevents others to put effort to answer to your question, because they see there is a _correct_ answer already. – holex Mar 12 '18 at 16:39
  • @BilalReffas In fact, I accept that answer because I think it is the right answer. Alamofire doesn't have any built-in option to manage that since it uses NSURLCache. It neither do, by the way, although it can be "hacked". Anyone interested may check the Anwuna answer on this post: https://stackoverflow.com/questions/19855280/how-to-set-nsurlrequest-cache-expiration/46158561?noredirect=1#comment85471895_46158561 – rmvz3 Mar 12 '18 at 18:02