Questions tagged [second-level-cache]

Second-level-cache, as the name implies, is a layer of cache that lives between a "primary" cache and a data service/store (relational database, in most cases) to optimize read operations on the service/store. It is different from the primary cache in its lifespan (primary cache being limited to a request lifetime) and capabilities (persist to store, clustering, etc.).

Second-level-cache, as the name implies, is a layer of cache that lives between a "primary" cache and a data service/store (relational database, in most cases) to optimize read operations on the service/store. It is different from the primary cache in its lifespan (primary cache being limited to a request lifetime) and capabilities (persist to store, clustering, etc.).

Second-level-cache is a concept most often encountered in the context of object-persistence frameworks, such as Hibernate. The idea is to allow the persistence engine to maintain a copy of entities that are available in the data service/store so that queries to retrieve them can be fulfilled using a local lookup as opposed to a full roundtrip to the service/store which invariably lives in a different server, thus requiring a network operation and incurring the associated overhead and latency/performance impact.

350 questions
4
votes
2 answers

Is there a way to look into L2 hibernate cache?

I have a task to attach Oracle Coherence (it is cache software) in my project. One way of using it is Level2 Hibernate cache. I want to see when hibernate takes results from L2 cache. How can i do that? Both ways will be good: listener of some sort,…
foret
  • 728
  • 6
  • 14
4
votes
3 answers

Second Level Cache - Why not cache all entities?

In my experience, I have typically used the shared cache setting: ENABLE_SELECTIVE My process is to then think about which entities are not expected to change often and those that would benefit from the cache,…
The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80
4
votes
1 answer

Is Hibernate second level cache useful for anything other than a "find by primary key" ?

From what I understand, the L2 cache is useful when finding an entity by using its primary key. But is there any point using it for queries that are not based on the primary key? E.g.: SELECT p FROM Person p WHERE p.age > 18 If the query cache is…
Pierre Duplouy
  • 2,415
  • 5
  • 23
  • 24
4
votes
0 answers

Doctrine Second Level Association Cache misses

--------------------- User Entity: /** * User * * @ORM\Table() * @ORM\Entity() * @ORM\Cache(usage="NONSTRICT_READ_WRITE") // .... /** * Cars of the user. * * @var ArrayCollection * @ORM\Cache(usage="NONSTRICT_READ_WRITE") *…
4
votes
0 answers

Hibernate second level cache - When can stale collection members be returned from the second level cache?

A colleague of mine and I have been having a debate as to when (if?) a collection cached in the second level cache can return stale data (we're using ehcache and hibernate 3.2.4 ). Here's the scenario: parent object P is cached and is an…
StevenWilkins
  • 1,313
  • 8
  • 18
4
votes
1 answer

How to get entries from the second level query cache?

In my grails application, I want to display all the current entries of the second-level cache from all regions. My code is as following : def getCacheStats() { StatisticsImpl stats = sessionFactory.statistics for (regionName in…
fabien7474
  • 16,300
  • 22
  • 96
  • 124
4
votes
2 answers

Hibernate database integrity with multiple java applications

We have 2 java web apps both are read/write and 3 standalone java read/write applications (one loads questions via email, one processes an xml feed, one sends email to subscribers) all use hibernate and share a common code base. The problem we have…
Austen
  • 131
  • 8
4
votes
1 answer

NHibernate not finding named query result sets in 2nd level cache

I have a simple unit test where I execute the same NHibernate named query 2 times (different session each time) with the identical parameter. It's a simple int parameter, and since my query is a named query I assume these 2 calls are identical and…
HokieMike
  • 655
  • 1
  • 7
  • 17
4
votes
0 answers

How to disable second-level cache invalidation on every native SQL query?

I store some entities that are not changed via Hibernate in Hibernate 2nd level cache. Also, I perform a lot of native SQL queries (updates) via Hibernate SessionFactory. Every time I execute native SQL query, second level cache is invalidated. Here…
Dmitry
  • 1,056
  • 1
  • 8
  • 17
4
votes
1 answer

Collections not read from hibernate/ehcache second-level-cache

I'm trying to cache lazy loaded collections with ehcache/hibernate in a Spring project. When I execute a session.get(Parent.class, 123) and browse through the children multiple times a query is executed every time to fetch the children. The parent…
4
votes
1 answer

NHibernate second-level cache using Redis vs just using Redis

My scenario is I prefer to stay in a relational database storage system like SQL Server because I would need to work with complex queries. And then, because some calculations would be better to be done overtime and just store the results into…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
4
votes
1 answer

Query Cache Hibernate loading entities

Can any one help me resolving this question. I am using Infinispan as second level cache and Hibernate as ORM. I have turned on both enityt and query cache. I have two queries, for example Q1 is "selet b from BokkEntity b where b.id < 5" and…
4
votes
2 answers

Hibernate Second level Cache <>

I want use second level cache in my hibernate Project but I just know a little about hibernate second level cache, can any one explain how shoud I use this in my code and what configuration and .jar file I need? I set these setting to my…
Am1rr3zA
  • 7,115
  • 18
  • 83
  • 125
3
votes
1 answer

Is/Can Hibernate's Second-Level Cache be Used for COUNT() operations?

When using Hibernate and Ehcache as a second-level cache (2LC) implementation, is (or can) this cache used when doing COUNT operations with a WHERE clause? In SQL terms the query I'm performing is SELECT COUNT(id) FROM table WHERE someColumn > 100.…
DeejUK
  • 12,891
  • 19
  • 89
  • 169
3
votes
1 answer

Hibernate and Ehcache- How to make sure every "select" goes through the entity cache?

I have an entity (JPA annotations with Hibernate query interface) which has a composite business key of two properties (an external-id and a subsidiary-id [that's a foreign key]) and a primary db key. I have a JavaSE multi-threaded process which…
Ittai
  • 5,625
  • 14
  • 60
  • 97