Reputation: 7358
I'm developing a pagerank checker widget. and i want to cache ranks. because on every page send a request to google takes takes a lot of seconds.
the general question: cache (store, save!) rank of each url (and get it afterward) in a database is faster and optimizer or in files? (1 file for all, or 1 file for each)
sorry for my terrible english
Thanks
Upvotes: 0
Views: 234
Reputation: 48387
It depends.
Have a read through this article by Chris Davis - particularly section 7.10. You should also have a think about the differences between speed and scalability.
While, in theory, the file based approach (using the directory hierarchy for indexing and one URL per file) will be faster, PHP does not have good facilities for managing concurrent file access. OTOH this is a key feature of a DBMS (be it relational or nosql). Another consideration is how you will be interacting with the data - you may not be retrieving it using the same indexing path as you stored it in (you can still implement multiple indexes with files, but its a lot easier in a database).
Upvotes: 1
Reputation: 18016
Cache the result is more better. Use mamchached or something like similar. You just need to first check that whether you have chached data, if so then don't send request to API and take data from there. But set time for cache (after that the cache will be destroyed). This will help you to synchronize your data with live. IF you have not cached data, then send request to api and store the latest data to cache. Its better in my opinion.
Upvotes: 0
Reputation: 2716
How about using something like memcached which stores the data in memory? If it's just cache, I don't see the downside.
Upvotes: 1
Reputation: 9413
Using files will be slower than using database ... As database uses several optimization's and best algorithms for storing and retrieving data , it is the best option to choose.. You can give indexing to your database and you can choose the database engine ( if using mysql ) as MEMORY (HEAP) Storage Engine for more faster performance..
Upvotes: 0
Reputation: 5761
Go with the database, and remember to enable indexing for columns you care about.
Upvotes: 1