Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
据我了解,L2 缓存在使用其主键查找实体时很有用。
但是将它用于不基于主键的查询有什么意义吗?例如:
SELECT p FROM Person p WHERE p.age > 18
如果查询缓存没有打开,L2 缓存还有用吗?
不,在那种情况下它没有任何用处。在通过 ID 获取实体时使用 L2 缓存,或者在通过 OneToOne 和 ManyToOne 关联导航时使用(这也会导致实体通过其 ID 加载,除非引用的列不是 PK)。