I have a youtube style site but it revolves around pictures.
On the homepage I want to show latest pictures that have been uploaded above the most popular pictures of all time.
Is it a good idea to do a database/cache query for every user when they hit the page in order to check what the lates开发者_JAVA技巧t images are and display them or should I do this another way to ensure the database isn't constantly flooded with requests for the latest posted pictures?
Maybe some sort of batch job?
Any ideas?
The most basic proactive thing you can do here is to cache the results of the DB query - either in your app code (less preferable) or in an existing piece of infrastructure integrate-able in your web "stack", for example something like Memcached:
http://memcached.org/
This has helped many a DB-backed site achieve some minimal level of scalability/performance.
Depending on your DB, you can also cache such queries as part of DB functionality itself, but it's better if you can intercept such things before they even get to the DB.
精彩评论