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
95
votes
5 answers

When and how to use hibernate second level cache?

I have trouble understanding when hibernate hits the second level cache and when does it invalidate the cache. This is what I currently understand: Second level cache stores entities between sessions, scope is the SessionFactory You have to tell…
palto
  • 3,523
  • 5
  • 32
  • 38
66
votes
2 answers

Caching with Hibernate + Spring - some Questions

I'm working on developing a web application with Spring 3 and Hibernate 3.6. At the moment I try to understand how Caching with Spring and Hibernate works. I found some sources about Caching with Hibernate and some about Spring and I try to bring my…
nano7
  • 2,455
  • 7
  • 35
  • 52
63
votes
6 answers

Spring Boot + JPA2 + Hibernate - enable second level cache

I'm using Spring Boot 1.2.5 with JPA2 to annotate entities (and hibernate as underlaying JPA implementation). I wanted to use second level cache in that setup, so entities were annotated with @javax.persistence.Cacheable I also added following in…
Daimon
  • 3,703
  • 2
  • 28
  • 30
38
votes
4 answers

Hibernate cache strategy

How do I decide which CacheConcurrencyStrategy to use? NonstrictReadWriteCache, ReadOnlyCache, ReadWriteCache, TransactionalCache. I read https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cache/CacheConcurrencyStrategy.html, but doesn't…
cometta
  • 35,071
  • 77
  • 215
  • 324
31
votes
9 answers

Why use your application-level cache if database already provides caching?

Modern database provide caching support. Most of the ORM frameworks cache retrieved data too. Why this duplication is necessary?
vbezhenar
  • 11,148
  • 9
  • 49
  • 63
28
votes
2 answers

What is second level cache in hibernate?

What is second level cache in hibernate ?
paku
  • 281
  • 3
  • 3
28
votes
6 answers

Hibernate 2nd level cache invalidation when another process modifies the database

We have an application that uses Hibernate's 2nd level caching to avoid database hits. I was wondering if there is some easy way to invalidate the Java application's Hibernate 2nd level cache when an outside process such as a MySQL administrator…
Dougnukem
  • 14,709
  • 24
  • 89
  • 130
25
votes
1 answer

How to clear the entire second level cache in NHibernate

I wish to clear the entire second level cache in NHibernate via code. Is there a way to do this which is independent of the cache provider being used? (we have customers using both memcache and syscache within the same application). We wish to…
Bittercoder
  • 11,753
  • 10
  • 58
  • 76
25
votes
1 answer

Removing objects from NHibernate second level cache

I just started thinking about using the NHibernate second level cache in one of my apps. I would probably use the NHibernate.Caches.SysCache.SysCacheProvider which relies on ASP.net cache. Enabling the cache was not a problem, but I am wondering on…
Max
  • 15,693
  • 14
  • 81
  • 131
20
votes
5 answers

Are entities cached in jpa by default?

I add entity to my database and it works fine. But when i retrieve the List, i get the old entity, the new entities i add are not shown until i undeploy the application and redeploy it again. This means are my entities cached by default? But, I…
TCM
  • 16,780
  • 43
  • 156
  • 254
18
votes
3 answers

EhCache + Hibernate Cache is not alive

After configuring EhCache v2.4.5 as the second level cache for hibernate v3.6.7 I get the following error while trying to load all objects of a particular entity using hibernate session. (There is no error for loading the objects for the first…
Saffar
  • 520
  • 1
  • 5
  • 13
16
votes
2 answers

Hibernate L2 cache. Read-write or transactional cache concurrency strategy on cluster?

I’m trying to figure out which cache concurrency strategy should I use for my application (for entity updates, in particular). The application is a web-service developed using Hibernate, is deployed on Amazon EC2 cluster and works on Tomcat, so no…
16
votes
2 answers

How to configure JPA 2.0 with Hibernate 3.5.2 to use EHCache as a Level 2 cache and query cache?

I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. edit// Is @Cacheable(true) enough for entity? Or…
Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
14
votes
6 answers

What are the pros and cons of a distributed second level cache versus focusing on tuning database

we have a website that uses nhibernate and 2nd level cache. We are having a debate as one person wants to turn off the second level cache as we are moving to a multi webserver environment (with a load balancer in front). One argument is to get…
leora
  • 188,729
  • 360
  • 878
  • 1,366
13
votes
1 answer

Why is NHibernate.Cache.HashtableCacheProvider not intended for production use?

The NHibernate documentation and the book NHibernate In Action state that the cache provider NHibernate.Cache.HashtableCacheProvider is not intended for production use. However, I could not find a reason for this. Does anyone know the reason?
Marco Eckstein
  • 4,448
  • 4
  • 37
  • 48
1
2 3
23 24