• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[NX:] caching records?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
Just started the SCJD assignment (Bodgitt and Scarper, Version 2.1.2)
As such, I am new to this forum, so please be lenient in case I'm not sticking to conventions that may be appropriate here.
Moreover, my native language isn't English, so you (and I) may get confused at times.
Now, I haven't seen a lot of posts regarding the caching of database records.
It seems that most of you are not implementing it this way.
Any particular reason for this?
The way I see it, keeping records in memory shouldn't really be a performance problem.
Let's say a client wants to see all contractors. This would require the server to lock the db file (for the duration of the entire read operation), read all records (I/O, so relatively slow) and create some kind of record Collection or Array (in memory!) to be sent back to the client. This Collection or Array would be of comparable size to the records kept in memory when caching (although only for a short while).
The way I see it, caching seems the better approach.
Then again, I haven't given it too much thought.
(The way I'm proceeding (for now) is to use 1 Data class (implementing the DB interface given by Sun))
Any comments would be highly appreciated.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Filip,

Now, I haven't seen a lot of posts regarding the caching of database records.
It seems that most of you are not implementing it this way.


I think the contrary : many people here seem to implement a cache, at least in its simplest form (caching all records in memory)

The way I see it, keeping records in memory shouldn't really be a performance problem.
Let's say a client wants to see all contractors. This would require the server to lock the db file (for the duration of the entire read operation), read all records (I/O, so relatively slow) and create some kind of record Collection or Array (in memory!) to be sent back to the client. This Collection or Array would be of comparable size to the records kept in memory when caching (although only for a short while).


Correct.
Best,
Phil.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Filip,
Welcome to JavaRanch.
Phil is correct - there are quite a few people caching their records. It is not really necessary, but it is a nice touch. Performance is one of those issues that is deliberately not detailed in the instructions - you won't get extra marks for making a high performance solution, but you could loose marks if your high performance solution is too difficult for a junior programmer to understand, or if you write code that really performs badly.
If you were concerned about potential memory issues, you could build your cache using SoftReferences which will allow the JVM to reclaim the memory if it really needs to.
Regards, Andrew
 
reply
    Bookmark Topic Watch Topic
  • New Topic