Reputation: 285
I have a main page in HTML which makes some Ajax calls (about 10) to a PHP file.
The PHP gets some data from different websites (via file_get_contents
) and outputs it as JSON. The average length of the output is 4000 characters. To not overload the number of request that my server makes to the websites, I would like to cache the response of same queries for something like 30-60 minutes.
The HTML main page contains a search input, so basically anything can be written and I may need to have a lot of different cache files. In this case, which method is more efficient, database storing (MySQL) or file?
Upvotes: 1
Views: 786
Reputation: 13
An important factor that hasnt been mentioned yet is the traffic on your website, caching has no use if you serve a handful of visitors an hour. Since you didnt specify it I assume you serve enough users that makes you consider caching.
In that case it will depend on your database speed, if you have a simple SELECT query and a relative small database I would not consider file/disk caching. Most likely running your query directly is faster than opening a file. If you have a complex query and a big database, we have 1 at work which is 100+ gigs big, than I would expect a file caching is better.
Memcache is fastest but it has limited storage, so best practise is to only store the most important things there that you want to have accessible on the fly.
Always add timers to your script and test the speed of multiple caching solutions against eachother.
Upvotes: 1