Hi everybody. I'm trying to add caching support (query cache) to a project which uses cayenne. For what I understood in the online documentation there are two types of caches: local and shared. Local cache is local to a data context (right?). But currently the application creates a new datacontext for every "transaction", so if I understood correctly the local cache is useless and I should use the shared cache.
Now... the problem.. I have a query cached (a sort of select * from table) and a new row is added in the table. I would like that the next time the same query is called also the new row is fetched. This is the query cache SelectQuery select = new SelectQuery(t); Class t; //this is the class of the persistent object to be fetched select.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE); select.setCacheGroups(t.getName()); This is my "sample" test code (Network is a Cayenne Object class) (GetAllNetwork is a selectquery with the above caching. AddNetwork adds a new object and commit it. A new DataContext is used every time) List<Network> networks = dbHandle.GetAllNetwork(); Network net = dbHandle.AddNetwork(); List<Network> newNetworks = dbHandle.GetAllNetwork(); assertEquals(networks.size() + 1, newNetworks.size()); Now... my assert is not true, because the query is cached. I also tried to add a listener (on postPersist, postUpdate and postRemove) to clear the cache for that particular group, but it does not work: private void clearCache(Object entity) { Persistent object = (Persistent)entity; QueryCache cache = ((BaseContext)object.getObjectContext()).getQueryCache(); cache.removeGroup(object.getClass().getName()); } Any help? Thanks Regards Francesco Romano