Hi
I have Company object and
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "company")
@Column(nullable = false)
Set<User> getUsers()
Do you recommend caching the getUsers collection performance wise?
Hi
I have Company object and
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy = "company")
@Column(nullable = false)
Set<User> getUsers()
Do you recommend caching the getUsers collection performance wise?
It depends on how frequently the getUsers()
method is being called by the users/user of your app. If at the moment getUsers()
is not causing a noticeable performance degradation in your app you can leave it as is. Otherwise you might consider making it cacheable and compare its impact on the performance of your app. Sometime caching can degrade performance of an app when you don't have enough memory allocated to your Java process (e.g Tomcat.)
There is no general answer to your question which depends on many criteria (is the object read-only? mostly read? read/write? how big are the collection? how is your memory doing? you many app server instances are you running per machine? etc).
I still suggest reading Collection Caching in the Hibernate Second Level Cache though.