Re: cached objects in the object context?
Andrus Adamchik <[email protected]> Mon, 20 Apr 2026 11:20:01 -0400
| Newsgroups | gmane.comp.java.cayenne.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Rob, Actually, "no cache" is the default strategy for every query. What may = remain cached after a query is related objects. So while you do not need = an explicit "cacheStrategy(QueryCacheStrategy.NO_CACHE)", you may need = to curate your prefetches to ensure the relevant subgraph is refreshed.=20= Andrus > On Apr 20, 2026, at 11:15=E2=80=AFAM, Robert A. Decker = <[email protected]> wrote: >=20 > Is it as simple as: >=20 > List<AiJob> jobs =3D ObjectSelect.query(AiJob.class) > .cacheStrategy(QueryCacheStrategy.NO_CACHE) > .where(... >=20 > I just want the entire graph of the fetch to be fresh each time. >=20 > Rob >=20 >=20 >> On 20 Apr 2026, at 13:49, Robert A. Decker <[email protected]> = wrote: >>=20 >> I have a couple of different systems modifying the database my = cayenne code is talking to. Every now and then I see behaviour that I = think says that something is being cached between database searches even = though I create a new context before each search: >> ObjectContext context =3D cayenne.newContext(); (cayenne is a = ServerRuntime built like at the end of this message) >>=20 >> Even though I'm creating a new context before the search, could the = server runtime that the context is built from be caching objects? If so, = should I wipe the cache before the search? Or is there a way to make = sure it doesn't work with a cache? >>=20 >> thanks, >> Rob >>=20 >>=20 >>=20 >> cayenneRuntime =3D ServerRuntime.builder() >> .addConfig("cayenne-project.xml") >> .addModule(binder -> >> ServerModule.contributePkGenerators(binder) >> .put(MySQLAdapter.class.getName(), = SmsPkGenerator.class)) >> .dataSource(DataSourceBuilder >> = .url(environment.getProperty("org.apache.cayenne.datasource.jdbc.url")) >> = .driver(environment.getProperty("org.apache.cayenne.datasource.jdbc.driver= ")) >> = .userName(environment.getProperty("org.apache.cayenne.datasource.jdbc.user= name")) >> = .password(environment.getProperty("org.apache.cayenne.datasource.jdbc.pass= word")) >> = .pool(Integer.parseInt(Objects.requireNonNull(environment.getProperty("org= .apache.cayenne.datasource.jdbc.minConnections"))), >> = Integer.parseInt(Objects.requireNonNull(environment.getProperty("org.apach= e.cayenne.datasource.jdbc.maxConnections")))) >> .build()) >> .build(); >>=20 >=20