java cache

The cache is actually containing "references" rather than the actual "objects", which are always sitting in the heap.

Cache is like a phone book, the phone number (reference) let you find the right person (object) faster and easier. The real person is not in the phone book. Just like other collections such as ArrayList, HashMap. BUT the difference is that it has eviction policy.

If you want to retrieve an cached object multiple times, and do operations on it, bear in mind that you are always operating on the same object in the heap.

So be careful,  you may need to "clone" the object for every retrieve based on your context.

posted on 2011-04-22 09:18  廉帅博  阅读(153)  评论(0编辑  收藏  举报