You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Peter Schröder <Pe...@freenet-ag.de> on 2007/01/03 14:02:20 UTC

clear caches

hi and happy new year,

i am looking for a method that tells cayenne to clear all cached objects, so that i can be sure the context will read fresh data from database next time a query is performed.

i found these:

	context.getEntityResolver().clearCache();
	context.getObjectStore().getDataRowCache().clear();

kind regards,
peter

Re: clear caches

Posted by Andrus Adamchik <an...@objectstyle.org>.
Actually running a SelectQuery would always result in fresh data,  
unless you explicitly set it to not refresh objects and/or use cached  
results.

Where the caching can bite you is reading objects via relationships  
or via DataObjectUtils. These would use cache. See my comments below  
on how to ensure those are invalidated.

> context.getEntityResolver().clearCache();

This is not needed - it clears cached mapping metadata, not the objects.

> context.getObjectStore().getDataRowCache().clear();

Yep - this one will clear shared cache. In addition, if you want to  
refresh everything, you would also need to replace DataContext with a  
new instance. Finally there is DataContext.invalidateObjects() method  
that allows targeted invalidation of specific objects.

Andrus



On Jan 3, 2007, at 3:02 PM, Peter Schröder wrote:
> hi and happy new year,
>
> i am looking for a method that tells cayenne to clear all cached  
> objects, so that i can be sure the context will read fresh data  
> from database next time a query is performed.
>
> i found these:
>
> 	context.getEntityResolver().clearCache();
> 	context.getObjectStore().getDataRowCache().clear();
>
> kind regards,
> peter
>