I am working on my bachelor's project and I'm trying to figure out a simple dilemma.
It's a website of a football club. There is some information that will be fetched from the website of national football association (basically league table and matches history). I'm trying to decide the best way to store this fetched data. I'm thinking about two possibilities:
1) I will set up a cron job that will run let's say every hour. It will call a script that will fetch the league table and all other data from the website and store them in a flat file.
2) I will use Zend_Cache object to do the same, except the data will be stored in cached files. The cache will get updated about every hour as well.
Which is the better approach?
Why can you not use both?
Have the cron job run a script that uses Zend_Cache?
Cache files can get deleted when system reboots and it then the website would have to load all external data and parse it, which would result in a very slow loading time for the unlucky user that visits the website right after the reboot.
Depending on the situation there isn't much of a difference. I like doing it on request (check cache expire time and rebuild) because there are cases where the data might not get viewed every day. If you have 5 million records, and only 50,000 actively get viewed, you are not bogging the system down with old data rebuilds.
Just a thought... might not even apply to your situation.
Why is your server rebooting?
A server should very rarely be rebooting.
zend_cache is just a front-end for things like memcache isn't it ?
If you plan on using something in memory such as memcache for the zend_cache object, then by all means use the zend_cache object if that's what you're comfortable with. You're probably still going to need the cron job to trigger the script using the zend_cache object on a schedule though.
If you're just going to use a flatfile back-end for the zend_cache object, you might as well just do your own thing and leave out the loading/instancing of the object though. Unless you plan on moving to something like memcache in the future, then it would be better to go with the zend_cache if that's something you're already comfortable using.
Then again, maybe I'm missing something. From what I understand though, zend_cache and cron aren't exactly related technologies functionality-wise.
Basically the problem with Zend_Cache is that on request, when the cache is dead, it must fetch and parse the data from external server which can result in a slower loading time (or when server reboots). However I made few tests and it seems the process of fetching and parsing the external data is rather fast so that might basically eliminate the problem.
If the rebuild process is rather expensive, then definitely do it at night via cron (which could even internally use Zend_Cache). If not, then just do it at run-time. Both are viable solutions it'll really just come down to your needs, which you have seemed to figure out now.
You could also call your front-end code through it as well, just incase for some reason the nightly cache is broken.