Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

how to cache objects MANUALLY

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

some o-r mapping tools can cache the objects that have been queried,then next time these objects are required,it don't need to access the database again,it can also monitor the database updating.
i wonder how i can implement such "cache" function MANUALLY? because i DON'T want to use ANY o-r mapping tools. i only use the jdbc to query database,then generate the object.

who can give me some clue?? or articles? or sample codes??

thank you!!!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caches are complex things. You might find it easier to use an existing caching framework rather than write your own. A quick google turns up this. No idea if its any good. �3000 per CPU too.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,i don't want the complex function,i only want to a simple one,who know the BASIC idea of the cache?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the most basic thing you could do is maintain some sort of Collection of already found objects. Suppose you have the objects User and Item. You could keep two Maps which hold the alread found objects. The idea could be that when you call some CRUD business method on either of these object types, it is the cache you go to first, if they are not there then its the DB you go to.

As I say this is very simple. You would have to code such issues as the cache becoming invalid - what happens for example if some other process deletes an object from the DB currently resident in your cache? You have think of what you do to stop the cache growing too big - perhaps have a defined limit of the number of entries possible in your cached Maps and push one out to put a new one in when you get to the limit. You would need to think carefully how you decide which object gets bumped out of the cache, otherwise this could make you cache more of a drain on performance rather than an aid. Your cache would not work in a cluster - so couldn't be used in a J2EE app (writing a clusterable cache is hard work). You might also have to decide at what point your cache commits objects to the DB - if it commits every object you update or insert straight away.

All this, since it is sort of "infrastructure" code, is usually best implemented by reusing an existing caching framework.
[ March 17, 2005: Message edited by: Paul Sturrock ]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something you can play with for a read-only cache:


[ March 18, 2005: Message edited by: Robert Hayes ]
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for all of your helps,let me try.
nowaday ,which o-r mapping tools support cluster environment?i learn that hibernate don't support it.
 
Robert Hayes
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe TopLink does...
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!