Hibernate supports the following caches: first level cache, second level cache, request cache
Yes.
Spring itself supports the following caching features: just caching methods
Spring 3.1 introduces a new annotation-based caching abstraction around methods, yes.
Level 1 cache is part of any Hibernate application.
Yes.
A Level 1 cache is created for EVERY hibernation session.
Yes, although you can manually clean it at any time.
What is stored in level 1 cache? Objects or just the values of their properties? queries and their results?
This is a map of all objects retrieved during the entire session, if you load the same object by id a second time, it will be loaded from L1.
I found out: the second level cache is used by ONCE for each application. isn't that so? Isn't it being used by ONCE per session? and: multiple sessionfactorys = can I use multiple second level caches?
You are right, usually there is only one factory session for each application (database), therefore there is a shortcut.
what is stored in the second level cache: in my opinion, only the values that belong to one record, and not the objects themselves.
The same as in L1, but they live longer. L2 is usually supported by some industrial capacity cache, and L1 is just a card (it should not even be thread safe). It stores complete objects, including lazily loaded relationships.
when saving values from one record in the second level cache, is it possible to save the values associated with it (from objects connected via a foreign key)?
You do not control L2 manually, this happens automatically.
when updating the values of one object in the cache of the second level, is it possible to update the values of related objects in the cache?
See above.
when the values of an object change, how can I update the second level cache? rinse? can i just update part of the cache or update the whole cache?
See above - Hibernate will come up with this for you. You never interact with L2 directly.
where does the second level cache make sense, and where not?
Measure. In an application that reads a large amount of data using a primary key and a read-write coefficient, it is very large, L2 significantly affects your performance.
Cache Mode: Does each cache mode support a different cache strategy? for example, in read-only cache mode, does the database and cache need to be synchronized? do other caching modes provide synchronization? I thought that synchronization should be done by the developer?
The caching mode helps Hibernate choose the best caching and invalidation strategy. For example, if the cache is read-only, Hibernate will not bother it invalid (or it will not do it often). But the read-only cache (read-only), of course, will prohibit any updates.
What is the difference between a request cache and a second level cache? in my opinion: cache sets are stored in query sets, but not with their values, only with their identifiers. when the query is used again and the result set is still “correct”, the values belonging to the identifiers are requested from the second level cache.
Exactly, but this is a very broad topic. Especially the result set is still the "right" part.
Should the 2nd level DOCUMENT be used in the query cache?
Yes, without the L2 request cache, there is no point and will drastically slow down the application.
Where does Query Cache make sense, and where is it?
The tough question is usually when you execute the same query many times and the universe of query parameters is low (for each set of query parameters a new query cache is created with all the record identifiers that are the result).
Does Spring provide more caching capabilities than method caching?
No, Spring is most or less suitable for your own code.
The caching method is not related to sleep caching.
Spring is not affiliated with Hibernate, so ...
but: for caching the method, a second level is needed, for example ehcache (which can also be used by sleep mode)
L2 is the concept of Hibernate. If you want to use caching methods, you need a basic cache. Let it be EhCache, it doesn't matter. Of course, it must be thread safe.
Can method caching be used without querying the database?
Spring has nothing to do with Hibernate. You can cache calculations that have nothing to do with the database.
if I use ehcache for sleep mode as a second level cache and ehcache for Spring for method caching, can I use the same ehcache instance? is there any chance that something is messed up?
To facilitate deployment, you can use the same CacheManager configuration and cache as Hibernate. As long as the cache names do not overlap, they are completely independent and even work in the same manager.
when using level 1 cache and level 2 cache, can they get confused? when querying the database, where does the result come from, level 1 or 2 cache? Does 1st level cache work with second level cache?
They just work until some kind of abstraction flows :-). When you request a primary key, L1 is checked first (it is faster), then L2.
anything else that could be confusing using the caches I mentioned ?:-)
See above, abstractions tend to occur. But the worst problems arise when you change the database, and Hibernate does not know about it. In addition, clustering without proper replication will cause a headache. And the biggest problem is that very often incorrect caching actually slows down the application (request cache is the most dangerous here).