aspose file tools*
The moose likes Performance and the fly likes Cache which supports generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Cache which supports generics" Watch "Cache which supports generics" New topic
Author

Cache which supports generics

Anitha Balasubramanian
Greenhorn

Joined: Sep 01, 2009
Posts: 1
I have used JCS in my code. But it requires me to typecast whenever i have to get any value from the cache. This is causing performance hit. So is there any other caching system available which will allow usage of generics so that typecasting is not needed?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

Anitha,
Welcome to JavaRanch!

Anitha Balasubramanian wrote: This is causing performance hit.

Really? Have you timed it? I would think a cast would be way less than repeating the thing you had cached.

Anitha Balasubramanian wrote:So is there any other caching system available which will allow usage of generics so that typecasting is not needed?

Generics still typecasts at runtime. It just avoids the need to type the typecast in code. Search for "type erasure" for more on this.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
There are actually some cases where generics improve performance, but I can only think of a few obscure situations where that might be the case. That said, i'd prefer a cache framework with generics for the simple reason that it's likely to result in more maintainable code.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

My argument is that everything is relative -- even if one operation is a few nanoseconds faster, it won't be notice if the values returned will actually be used. Meaning... if all you have is a tight loop that did nothing but call the cache code, then maybe, there is a chance you'll notice that it may be slower.

Since, in most cases, applications call the cache to fetch data, to actually do something with it, I highly doubt that there is a performance hit here.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
Henry Wong wrote:My argument is that everything is relative -- even if one operation is a few nanoseconds faster, it won't be notice if the values returned will actually be used. Meaning... if all you have is a tight loop that did nothing but call the cache code, then maybe, there is a chance you'll notice that it may be slower.

Since, in most cases, applications call the cache to fetch data, to actually do something with it, I highly doubt that there is a performance hit here.

Henry


I completely agree. I was just making the (fairly useless) observation that generics can in fact result in slightly better performance in some cases, and since we're in the "Performance" forum ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cache which supports generics