Hi, everyone,
I've found a way, although I'm not sure it's the best way to do it.
I implemented a CustomEntityPersister, extending the
SingleTableEntityPersister. In this new class, I overwrote the protected
update method, inherited from AbstractEntityPersister, and in the new
implementation I verify which fields are dirty and, if they match the
ones I want to be stale-tolerant, I set a flag so that later, when
Hibernate queries which spaces are modified by the persister (via
getPropertySpaces), I return an empty array.
Any comments?
Thanks for the help.
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.br
Hi Joe,
Is it really possible? If so, how can I do it?
We are trying to use the QueryCache more effectively, that's why we are thinking of hacking the cache system. There's this User model with the lastLogin attribute that is changed every time the user logs into the system. And then, every time an user logs in, all the cached queries related to the User model are invalidated. And most of the cached queries are related to this model.
Any other idea?
Thanks
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.br
On Mon, Apr 4, 2011 at 4:25 PM, Haswell, Joe <josiah.d.haswell@hp.com> wrote:
Hi Luiz,
Sorry, I didn’t read back through the thread in its entirety before responding. A cached result is by definition invalid after the backing store has been modified in any way. It is possible to override this behavior, but is that either necessary or desirable? If this is a performance consideration, you should assess whether the default performance is acceptable before trying to improve it. I think selectively disabling cache-invalidation is always going to look a bit hacky because it contravenes the cache-store contract.
Thanks,
Joe H. | HP Software
From: sr.saude@gmail.com [mailto:sr.saude@gmail.com] On Behalf Of Luiz Fernando O. C. Real
Sent: Monday, April 04, 2011 1:01 PM
To: Haswell, Joe
Subject: Re: [hibernate-users] Stale query cache by column
Hi, Joe
Sorry, I think I didn't make myself clear. I understand that I can listen for the update to a particular table, but the event, AFAIK, is triggered after the cache invalidation, and I would like to not invalidate the cache for a specific update.
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.br
On Mon, Apr 4, 2011 at 3:50 PM, Haswell, Joe <josiah.d.haswell@hp.com> wrote:
I’m not entirely sure I understand what the problem is. You could certainly create your own event-listener that listened for an update to that particular table. From my understanding of the problem, the cache becomes invalid immediately after an update occurs, which is when your event-listener would be triggered. This seems to me to be the correct time to invalidate your cache. Caches can be invalidated programmatically by Hibernate (which is what I suspect you’re seeing), or you can invalidate them manually. If Hibernate’s default cache-invalidation is unsuitable, can you override it with appropriate semantics?
Joe H. | HP Software
From: hibernate-users-bounces@lists.jboss.org [mailto:hibernate-users-bounces@lists.jboss.org] On Behalf Of Luiz Fernando O. C. Real
Sent: Monday, April 04, 2011 12:39 PM
To: hibernate-users
Subject: Re: [hibernate-users] Stale query cache by column
Hi, again
Thanks for the reply, Joe. I've checked out the event system and could not find anything helpful. It seems that the generated events are only fired after the cache is invalidated.
I've found a way to do this implementing a QueryCache, but it's not the most elegant solution. I verify the query to be retrieved from the cache via the toString() method in the QueryKey object. If the SQL matches the one I'm trying to turn stale cache tolerant, I ignore the timestamp.
Is there a better way to do this, to look at the query being passed? Wouldn't it be nice to have a getter for it in the QueryKey class?
Thanks
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum | Ensino e Inovação
http://www.caelum.com.brOn Thu, Mar 24, 2011 at 12:16 PM, Haswell, Joe <josiah.d.haswell@hp.com> wrote:
I’d check out the event system. If a particular event invalidates your cache, just clear it or the region of it that’s invalid.
Joe H. | HP Software
From: hibernate-users-bounces@lists.jboss.org [mailto:hibernate-users-bounces@lists.jboss.org] On Behalf Of Luiz Fernando O. C. Real
Sent: Thursday, March 24, 2011 9:06 AM
To: hibernate-users
Subject: [hibernate-users] Stale query cache by column
Hi,
I'm trying to implement a custom QueryCache that, like the example in http://community.jboss.org/wiki/QueryCache, does not invalidate some existing register is updated in a specific table. However, unlike the example, I'd like to do that by analyzing which columns were changed in an update.
More precisely, I have an User table, which has a lastLogin column. I'd like to keep the QueryCache valid when I update the lastLogin of an User.
I haven't found any way to do that yet. Is that possible?
Thanks in advance.
--
Luiz F. O. Corte Real
Vida Geek
http://vidageek.net
Caelum Objects
http://www.caelumobjects.com