For best execution speed, should I cache in Main memory or keep querying the Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vpawizard
    New Member
    • Nov 2006
    • 66

    For best execution speed, should I cache in Main memory or keep querying the Database

    Hello,
    In my application, I need to read data of two sizes - about 10 bytes and 5-50KB. I need optimum performance of my application - speed is my main concern. Would it be wise to read 10 bytes from database and 5-50KB data from main memory(this data is read from database and cached in memory)?
    Please suggest. Thanx in advance.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to make it a little more descriptive.

    Heya, vpawizard.

    Ultimately, it is faster to cache results and serve them from memory. However, you want to be careful, because:
    • Caching results that you'll only need once wastes time and memory.
    • Caching results that are too large could result in out-of-memory errors.
    • Caching results only works if the data in the database remains the same. You'd have to be able to check to see if the data in the database has changed (keep in mind that you might have multiple instances of the app running on the same system in the case of a multi-User or webserver setup).


    Many database servers already cache results. So if you run a query twice, and nothing has changed in the result set, the second query will execute almost instantaneously .

    Comment

    Working...