aspose file tools*
The moose likes Performance and the fly likes How cache can improve performance in this way? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "How cache can improve performance in this way?" Watch "How cache can improve performance in this way?" New topic
Author

How cache can improve performance in this way?

Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
I am recently working on Jboss cache, and suddently I have a question:

when we are saying "putting things into cache", are the "things" actual objects or just references?

my friend said it's reference that setting in cache, is that true?

If cache is storing the reference, how is that going to help to improve performance?


** SCJP 5.0 84% **
** SCWCD 1.5 76% **
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Of course its a reference variable.

Note that in order for a cache to correctly handle discarding old references when memory is needed, your code must not keep any other reference.

Speed up comes from the difference between creating a new object - possibly reading a file for example - and finding that object already in memory.

LOTS of effort has been put into a variety of Java cache implementations, going all the way back to JSR-107.

Bill
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
William Brogden wrote:Of course its a reference variable.

Note that in order for a cache to correctly handle discarding old references when memory is needed, your code must not keep any other reference.

Speed up comes from the difference between creating a new object - possibly reading a file for example - and finding that object already in memory.

LOTS of effort has been put into a variety of Java cache implementations, going all the way back to JSR-107.

Bill


SO.. cache is not a place to putting the objects ? just their references?

cache is like a box contains many people's contact cards, and the actual people can be anywhere, cache is just make us easier to 'find' the person?

right?
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Chrix Wu wrote:
SO.. cache is not a place to putting the objects ? just their references?
cache is like a box contains many people's contact cards, and the actual people can be anywhere, cache is just make us easier to 'find' the person?
right?


In Java, if you declare a variable:
Object var = new Object();
the variable stores a reference to the object, not the object itself.
The object itself is stored in the heap.

Similary, if you declare an array and collection, they store references to objects, not objects.

A cache is a kind of collection (or map, or array - depends on implementation)
- and like variables, arrays and collections - it stores references to objects, not objects.
Objects are always stored in the heap.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
cache is like a box contains many people's contact cards, and the actual people can be anywhere, cache is just make us easier to 'find' the person?


Not exactly.

If you want a paper analogy, a cache is more like a box on your desk of "current cases" where you keep copies of the contacts for currently active problems so you won't have to go back to the file room every time you get a call. At the start of the week this box might be empty, it gets new entries as problems come up and if a contact has not been used in a while it gets discarded, but there is always a master copy back in the file room.

Bill
Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
William Brogden wrote:
cache is like a box contains many people's contact cards, and the actual people can be anywhere, cache is just make us easier to 'find' the person?


Not exactly.

If you want a paper analogy, a cache is more like a box on your desk of "current cases" where you keep copies of the contacts for currently active problems so you won't have to go back to the file room every time you get a call. At the start of the week this box might be empty, it gets new entries as problems come up and if a contact has not been used in a while it gets discarded, but there is always a master copy back in the file room.

Bill


thanks. so i can say that cache is a special collection, which contains object references, and has eviction policy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How cache can improve performance in this way?