Second-Level Cache — Concept Check
Questions on Second-Level Cache. The second-level cache (Ehcache, Caffeine, Infinispan) caches entities across sessions; annotate entities with @Cache and configure region expiry to avoid stale reads.
Questions in this quiz
7 questions on Second-Level Cache — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices that updates to a product's price via a direct SQL query are not reflected in the application. What is the likely issue?
- AThe query cache is not configured properly.
- BThe application is not using any cache.
- CThe second-level cache is not being invalidated.
- DThe first-level cache is not being used.
2.Which annotation is required to enable second-level caching for an entity in Hibernate?
- A@Cache
- B@Cacheable
- C@Entity
- D@Table
3.A developer configures a collection with @Cache(usage = CacheConcurrencyStrategy.READ_WRITE). What does this imply?
- AThe collection is immutable and cannot be updated.
- BThe collection can be safely updated without stale data issues.
- CThe collection does not require caching.
- DThe collection will never expire from the cache.
4.After a bulk update using JPQL, what must be done to ensure data consistency in the cache?
- AReconfigure the query cache settings.
- BDisable the second-level cache temporarily.
- CIncrease the cache timeout settings.
- DManually evict affected entities from the cache.
5.A service using Hibernate slows down due to frequent database hits. Which configuration could improve performance?
- ADisable the first-level cache.
- BEnable the second-level cache for entities.
- CIncrease the session timeout.
- DUse native SQL queries exclusively.
6.Which statement about the query cache in Hibernate is true?
- AIt never expires cached data.
- BIt caches entire entities, not just IDs.
- CIt is enabled by default for all queries.
- DIt is invalidated by any change to the queried table.
7.What is the main risk associated with using the second-level cache in Hibernate?
- AInability to cache immutable data.
- BStale data due to direct database updates.
- CSlower application startup.
- DIncreased memory usage.