If all I need to do is cache POJOs to save session information, what is the benefit of using some separate technology to cache them like Infinispan
instead of just using a static class to store and retrieve them?
Asked
Active
Viewed 188 times
-1

the beest
- 463
- 6
- 26
-
@Kayaman thanks for your non-constructive response to my question. what would we do without you – the beest Jun 01 '16 at 14:11
-
@Kayaman really? a bad question? first of all, you could of just not responded at all, but clearly you'd rather seek validation for your non-constructive opinions than actually be constructive. i think somebody wants some more attention in their life? spoiler alert. it's you. secondly, who are you the riddler? are you the master of questions? nobody cares if you think a question is bad or good, it's such a subjective metric you might as well keep it to yourself because it's completely useless for purposes other than exposing just how ignorant the people who share it are – the beest Jun 01 '16 at 14:57
1 Answers
1
Basically, Infinispan is a distributed key-value data store, so that if you put something on one machine running infinispan, you'll get the same value on other machines.
Static classes will work only in the same machine. Of course there are also limitations of static (undefined lifecycle, bad testability for example) and so forth, but its a different story.
If you need an implementation of cache in the single machine, than you don't need infinispan (or Redis, or Hazelcast or... there are a lot of solutions). Instead you can find that guava cache suits your needs. There are other possible solutions as well here.

halfer
- 19,824
- 17
- 99
- 186

Mark Bramnik
- 39,963
- 4
- 57
- 97
-
so the reasons i would use guava cache over a static class is because static classes have limitations such as undefined lifecycle and bad testability? and those are the only reasons, or most significant reasons, regarding differences in effectiveness of the two options? – the beest Jun 01 '16 at 14:02
-
Not exactly. When you're talking about caches you use notions like "hits/misses" and so on. Cache is not just storing everything in memory, its more complicated. You can implement the cache functionality by yourself or use a well-tested and wide-spread solution that other people have already created (such as guava cache). In any case if your application is not a distributed, Infinispan is an overkill – Mark Bramnik Jun 01 '16 at 14:05
-
i thought `Infinispan` could be run locally in an application as well as in a distributed fashion. why didn't you list that as an option in your answer in contrast with `Guava`? – the beest Jun 01 '16 at 14:09
-
I didn't say you can't run it. Actually you can run in for one application, but its all about the distributiveness, it has network synchronization algorithms and so forth. All I'm saying that for one server its an overkill. – Mark Bramnik Jun 01 '16 at 14:14
-
what if in my web application there are news articles and each news article has a vote tally. would `Infinispan` help me if i had a news article cached with it and two people tried to upvote the news article at the same time? – the beest Jun 01 '16 at 14:29
-
It really depends on your design. For caching - yes, although I tell you again, if you run in one machine its just too complicated, easier things will work better. But all-in-all I would go for database here (relational or not), so you should peek the right technology for your requirements. – Mark Bramnik Jun 01 '16 at 14:34
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113546/discussion-between-the-beest-and-mark-bramnik). – the beest Jun 01 '16 at 15:14