Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cache which supports generics

 
Anitha Balasubramanian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic