简体   繁体   中英

Spring + Hibernate web application - When to use cache?

I'm building java web application which in future can generate a lot of traffic.

All in all it uses some quite simple queries to the database but still some kind of cache may be necessary to keep low latency and to prevent high database access rate.

Shall I bother with cache from the start? is it necessity? Is it hard to implement or use some open source solutions on existing queries and how such cache will know when database state changed?

It all depends on how much traffic you expect, do you have some estimate of the max volume or the number of users?

Most of the times you don't need to worry about the cache from the beginning and can add later a hibernate second level cache later on.

You can start the development without a cache configured, then add it later on by choosing a cache provider and plug it as second level cache provider. EHCache is a frequent choice.

You can then annotate your entities with @Cache with different strategies, for example read only, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM