Main problem:
- Application caches URL's from facebook photo CDN
- The photos expires at some point
My "technical" problem:
- Facebook CDN "expires" header doesn't seem to be reliable ( or i don't know how to deal with them )
Using CURL to retrieve expiration date:
curl -i -X HEAD https://scontent-b.xx.fbcdn.net/hphotos-xap1/v/t1.0-9/q82/p320x320/10458607_4654638300864_4316534570262772059_n.jpg?oh=9d34386036754232b79c2208c1075def&oe=54BE4EE2
One minute before it returned:
Mon, 05 Jan 2015 01:34:28 GMT
Calling it again now returned:
Mon, 05 Jan 2015 01:35:27 GMT
Both times "Cache-Control" returned the same:
Cache-Control: max-age=1209600
So far:
- It seems like one of the most reliable ways would be to have a background job checking the photos all the time, but that feels a bit "wrong", like "brute forcing".
- Having a background job would potentially allow expired pictures to be served up to the moment this photo url is "renewed"
My questions are:
- Should i use the max-age parameter even tough it doesn't seem to change?
- Is there a reliable way of using facebook's CDN URL?
- Any other idea of how this should be implemented?
- < joke >Should facebook API be used to punish badly behaving coders?< /joke >
Possible solutions ?
Check facebook for the most recent URL before serving any CDN URL
~> would slow down my requests a lot
Have a background job renewing the URL and expiration dates
~> would potentially have expired photos while the job don't "catch" them
Download the photos to my own CDN
~> not a good practice i would guess
UPDATE: ~> Perhaps Tinder actually cache user's pictures on their own CDN: https://gist.github.com/rtt/10403467 so seems like facebook is kind of OK with it?