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
13
votes
2 answers

How to know/log whether Hibernate 2nd-level cache was used or not for a query?

Currently, in order to check if the Hibernate 2nd-level cache was used for a Database query, I check my SQL log (through p6spy or logSql=true in Datasource.groovy) to see if the Grais/Hibernate triggered an SQL query. And I assume that if the query…
fabien7474
  • 16,300
  • 22
  • 96
  • 124
13
votes
1 answer

Hibernate: batch_size? Second Level Cache?

I have a Hibernate domain object that gets loaded by different parts of the application. Sometimes it's advantageous to lazy load every association and others it's better to load the entire thing in one join. As a hopefully happy compromise I've…
davidemm
  • 2,001
  • 1
  • 23
  • 31
13
votes
2 answers

NHibernate and Memcached - should use_minimal_puts be enabled?

I use NHibernate with Memcached as a second level cache and have always been curious about the cache.use_minimal_puts configuration option. According to the documentation: hibernate.cache.use_minimal_puts: Optimizes second-level cache operation to…
DanP
  • 6,310
  • 4
  • 40
  • 68
12
votes
2 answers

When overFlowToDisk gets activated in EHCACHE?

I have some questions on "overflowToDisk" attribute of element? 1) I read at this URL that : overflowToDisk sets whether element can overflow to disk when the memory store has reached the maximum limit. "Memory" above refers JVM memory allocated…
Vicky
  • 5,380
  • 18
  • 60
  • 83
12
votes
1 answer

NoCacheProvider class alternative in Hibernate 4

I've just realized that there is no org.hibernate.cache.internal.NoCacheProvider class in Hibernate 4 Core packages. Maybe it is deprecated. So is there any alternive for Hibernate 4? Thank you in advance!
sidlejinks
  • 709
  • 1
  • 9
  • 25
11
votes
2 answers

How hibernate ensures second level cache is updated with latest data in database

I have read that using hibernate's second level cache, it can improve applications performance by having less database hits for data / object retrieval. However, how does hibernate ensure that second level cache is up to date with the data in…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
11
votes
3 answers

Second level cache vs query cache vs collection cache?

As per my understanding, Second level cache will be used when the objects are loaded using their primary key. This includes fetching of associations.I can think of only above session.get(), session.load methods where second level cache will come in…
M Sach
  • 33,416
  • 76
  • 221
  • 314
11
votes
2 answers

Can we use JPA2 annotations to cache associations?

I'm now using the JPA2 @Cacheable annotation on my Entities, and all is working well. I now need to cache a ManyToOne association. In classic Hibernate, it was necessary to annotate the association with @Cache.…
Dick Chesterwood
  • 2,629
  • 2
  • 25
  • 33
10
votes
3 answers

Why is my entity not evicted from my second-level cache?

I’m using Hibernate 4.3.11.Final with Spring 3.2.11.RELEASE. I’m confused as to why my cache eviction isn’t working. I have this set up in my DAO … @Override @Caching(evict = { @CacheEvict("main") }) public Organization save(Organization…
Dave
  • 15,639
  • 133
  • 442
  • 830
10
votes
3 answers

Hibernate query cache - for objects not in the 2nd level cache - risky? useful? bad practice?

Related to this question Premise: These are my assumptions, based on my reading, experience and understanding, they may be wrong, if they are, please comment and I'll edit the question. Query cache is good mostly along with 2nd level cache Query…
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
9
votes
1 answer

Hibernate second-level cache composite-id

I am trying to cache an object in Hibernate's second level cache that has a composite-id mapped in my persistence-mapping file. The logs say that the first time I run the query, the class mapped as the composite-id is put in the cache. However,…
sma
  • 9,449
  • 8
  • 51
  • 80
9
votes
3 answers

Hibernate: Clean collection's 2nd level cache while cascade delete items

I have a problem Hibernate does not update 2nd level cache for a collection of items which are subject of cascade removal. Details Assume we have an object Parent which has Parent.myChildren collection of Child objects. Now we have also object…
Yurii Soldak
  • 1,458
  • 4
  • 19
  • 24
8
votes
2 answers

Nhibernate 2nd level caching issues / questions when moving from a single web server to a multiple web server load balanced environment

My previous setup was a single web server and a single database server. I was using nhibernate 2nd level caching to cache stuff to avoid lots of calls going to the database. This has worked great as i was using this this assembly…
leora
  • 188,729
  • 360
  • 878
  • 1,366
8
votes
2 answers

Working example of Hibernate 3.6.2 2nd level caching with JPA2?

The title obviously states it : I can't make the second-level cache work for JPA2/Hibernate 3.6.3. I've been trying many a hack to make it work. But I'm only succeeding in having the query cache working. Although Hibernate creates the caches (name…
Jan Goyvaerts
  • 2,913
  • 4
  • 35
  • 48
8
votes
3 answers

NHibernate caching entities across sessions using SysCache

I'm developing a web application and I would like caching to persist across web requests. I am aware that the first level cache is per-session only. I have second-level caching enabled and this is working for queries. However, the second-level…
Chris Haines
  • 6,445
  • 5
  • 49
  • 62
1
2
3
23 24