• 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

How cache can improve performance in this way?

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic