I’m using ehcache to cache entities using hibernate.
Looking at ehcache monitor, everything seems to work fine (flush put cache count to zero, and reload put count back in one), but if i change some value directly on the db and reload, the updated value is showed and not the cached one. I dont know if this is the expected behaviour, but it will be strange as a cache to act like that.
I’ve tried every solution found to figure this out with no success.
This is the expected behaviour. The database is the source of all correct data the cache is just there to speed up access to the data in the database. If the data differs then the cache is wrong by definition.
So if you reload the cache is reloaded from the database.
If you save data through Hibernate then the data is written to the cache and the database. There can be an issue here when you have more than one thread/process reading or writing. For how to manage this see caching strategies in the Hibernate documentation
In general updating the database directly causes issue the cache will not have the correct data unless it is notified that it must invalidate the data it has and/or reload from the database.