1

I read about JSR 107 Caching (JCache).

I'm confused: From what I know, every CPU manage his caching memory (without any help from OS).

So, why do we need Java Caching handler ? (if the CPU manage his own cache)

What I miss here ?

Thanks

2 Answers 2

2

This is about caching Java objects, like objects that are expensive to create, or need to be shared between multiple Java VMs. See https://jcp.org/en/jsr/detail?id=107

A cache is generally used to temporarily keep data between uses because it takes too much time or is plain impossible to recreate if you just throw it away between uses.

The CPU cache keeps data and instructions in case it has to access it again, because reading it from memory takes more time.

The JSR 107 cache works o a completely different level.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks. If I'm using pools, and creates all the objects at start up (and not at run time), Do I need to use JCache too ? (Is it will be efficient to use JCache in that scenario ?)
I'm not that familiar with JCache. Using pools is also a kind if caching. If a simple pool works for you, go for it. If it is really the best design is impossible to say without a lot more information on your application.
I'm storing objects at pools, but I'm not sure that always the data is stored on cache and not on RAM...
All your objects are in the RAM. Since your pools, and JCache both use objects they are also in RAM.
OK, so there is no difference, because JCache use RAM and not actually CPU cache ?
|
1

There is a difference between CPU caching and memory caching. This JCache would cache things in memory so you don't have to get it from an expensive resource like disk or over the network.

So CPUs have caches built into them so that they can avoid going to memory. CPUs commonly have three levels of cache and store around 8MB. CPU caching is not something you have to worry about because it is taken care of for you. If something isn't in the CPU cache then it has to go fetch it out of memory.

Caching in memory is to avoid going to disk or even slower resources as I mentioned earlier. This mechanism programs have control over. So if you want to avoid continously asking your DB for some object you can store it memory and keep returning the same object. This saves quite a bit of performance. As Thomas mentioned JCache adds the functionality to be able to provide caching across JVMs. From what I understand this means that different Java programs can share the same cache.

2 Comments

Can you please be more informative. CPU cache would do the same: cache thing in memory so it will no have to get it from RAM (expensive resource), so what is the different ?
CPU cache is limited to 8MB and you are not in control of it. You have plenty of memory, gigabytes of the stuff and you are in control of it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.