The online racing simulator
How do I properly cache data fetched from LFSW Pubstat?
Hi People, and happy new year

I am wondering about what is the best way to cache data from lfsw. I am currently simply checking if a stats-cachefile older than 5 minutes exists for this LFSW-Name and grab the PST-Stats from pubstat if not. Of course this is no good way of caching - but how do I do a proper caching?

Greetings, Stalker

PS: Please excuse me if I wrote some crappy English above - I am slightly drunk b/c of a new-year-party I just came back from.
That's ok, I'm still drunk ...


I would, if your using PHP, parse the results from LFSWorld into an array (via LFSWorldSDK if you wish, you don't have to use it, as I made that program, I would use that.) then save the array to the file with serialize function.


<?php 
file_put_contents
($unameserialize($sdk->get_pb($uname)));
?>

that sounds good for a beginning, but that still not prevents me from stepping into the tarpit-limit, doesn't it? I am currently offering custom status-sigimages for my team-members, and if more than one person uses them as
signature in one forum-thread, it will still lead to the "tarpitted"-message for one of them. any idea for this? I currently really ran out of useful ones.
The only nice way to get around this is to cough up for premium stats.

However, here are some nasty hacks that will allow you to do this without premium but it means more work on your part.

The simplest of these is to make a request to LFSWorld and check to see if you got the tarpit error message. If you did then sleep(5) and make the request again.
This method sucks because it means slow loading images for some poor soul and if multiple team members post in the same thread with one of your images in your sig....
1: request data from lfsworld for member
2: check result for tarpit error
3: if error, sleep(5); goto 1

The next method requires your host to support cron jobs.
Simply write a script that fetches all data from lfsworld and puts it in the cache. Change your sig script to only fetch data from the cache and add the request scripts to your hosts crontab to run every X hours or however often you want it to update (min time is (teamMembers * 6) ... 6 incase the network is running a little slow).
Request script
1: foreach teamMembers as member
request pst data from lfsworld
write data to cache
sleep(5)

Final method is a variation on the one above if your host doesn't support cron.
Do pretty much the same as above, only this time the request script must be accessible by URL.
The request scripts touches itself and this will act as a marker for the last lfsworld request time.
The sig generating script only fetches data out of cache again, but this time also checks the last modified time of the request script. If it was last modified over 'updateInterval' seconds ago then it makes a GET request to your request script, thus triggering it to update the cache.
Request script
1: if(time() - filemtime(__FILE__) < updateInterval
die();
2: foreach teamMembers as member
request pst data from lfsworld
write data to cache
sleep(5)
3: touch(__FILE__)

Sig script
1: get all pstdata from cache
2: if time() - filemtime(LOCAL_PATH_TO_REQUEST_SCRIPT) > updateInterval
fclose(fsockopen('URL_TO_REQUEST_SCRIPT'))

Again, the best way to do this is through premium stats ... it's not like its expensive

FGED GREDG RDFGDR GSFDG