Hello all,
Two questions:
1. How do I manually refresh ehcache?
2. Is there an intelligent way to set a
Code:
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
element to READ_WRITE for the scope of a single transaction?
I am a developer on a very large project with 20 nodes in the cluster and 30 entities in the domain model (Hibernate 3.2, Tomcat 5.5, JDK5). Like most applications I've worked with, the vast majority of our data is read-only 99% of the time. Think of it as an e-commerce application. The merchandise is read-only until updated by a feed, perhaps once a week.
Under the assumption that a read-only cache is more cluster friendly and performs faster with less overhead, wouldn't the ideal be to set the read-only attribute at query time and make it writable only when the feed executes, manually updating the cache afterwards?
I assume this solves clustering issues since the db is never updated by any other process. I assume EHCache is lighter and more responsive than a cluster-aware cache. I also assume that READ_ONLY will perform faster than READ_WRITE. Ideally, I'd not like to maintain 2 complete sets of mappings, but instead the delta between them (assuming there's no programmatic way of doing so).
I've tried a few approaches with no success.
Approach 1: override at the session
First of all, I tried setting an entity to
Code:
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
and making it writable using
Code:
session.setCacheMode(CacheMode.IGNORE)
during the session I was attempting to write to the entity. It didn't override the READ_ONLY attribute.
Approach 2: Inheritance.
If I can't programmatically override the caching READ_ONLY attribute, I'd be happy to extends each class and create a read/write instance of each class if it meant not duplicating any unnecessary mapping elements.
I tried creating an entity named ItemRO which works great, but
Code:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
ItemRW extends ItemRO{
}
is not an option. I assume there's no simple way to extend the working class and change one property.
Thanks in advance,
Steven