> But when I make the same query (now that the code has created the item), I'm 
> getting an empty result again. 

Is that item committed? Queries are run against the DB and won't see items that 
haven't been committed.

Also in general an app would invalidate cache by cache group. This way you 
won't need to know the cache key of a query, and can invalidate multiple 
queries at once.

Andrus


On Aug 4, 2011, at 5:10 AM, Joseph Senecal wrote:

> Using Cayenne 3.1M2
> 
> When a cached query for a single record returns no entry, I'd like to remove 
> that single result from the cache. Either the code will be creating the 
> record, or it will be manually added and I want the code to notice when it 
> is. It looks like this should be possible using this code:
>                               DataContext dataContext = (DataContext) context;
>                               String key = 
> query.getMetaData(dataContext.getEntityResolver()).getCacheKey();
>                               dataContext.getQueryCache().remove(key);
>                               assert 
> (dataContext.getQueryCache().get(query.getMetaData(dataContext.getEntityResolver()))
>  == null);
> 
> 
> And when I run the code the assert confirms that the entry has been removed.
> 
> But when I make the same query (now that the code has created the item), I'm 
> getting an empty result again. 
> 
> I'd prefer not to have to flush the entire table cache whenever I create a 
> new entry, is this possible?
> 
> Joe

Reply via email to