sunafi
sunafi

Reputation: 11

hibernate cache expiration after days

Application is using Hibernate 3 and needs to cache data while saving to the database.

  1. Is it possible to cache only a few columns of an entity, instead of all?

  2. Is it possible to set expiration time of an entity after a few days? For example, is it possible to set expiration time to 3 days, so that records can be auto-removed from the cache after 3 days?

I have started looking into caching process but not sure if the above two needs can be fulfilled.

Upvotes: 1

Views: 1404

Answers (2)

Rohit Jadhav
Rohit Jadhav

Reputation: 165

1) YES, Make other fields Transient, so they will not take part in second level caching pr

Upvotes: 0

Dragan Bozanovic
Dragan Bozanovic

Reputation: 23552

  1. No, it is not possible to cache only a subset of columns for an entity in the Hibernate second-level cache, as otherwise Hibernate would need to go to the database to fetch the remaining data when assembling such entity instances anyway, thus defeating the purpose of the cache.
  2. Yes, it is possible to set expiration time for cached data. Hibernate leaves it to up to the L2 cache provider to manage expiration and eviction policy, so you need to configure it there (consult the documentation of the cache provider you use).

More details here and here.

Upvotes: 1

Related Questions