Re: cached objects in the object context?

"Robert A. Decker" <[email protected]> Tue, 21 Apr 2026 09:26:47 +0200
Newsgroups gmane.comp.java.cayenne.user
Message-ID <[email protected]>
I went through the api documents (imagine that these days...) and found =
that this is the equivalent of invalidateAllObjects:
context.invalidateObjects(context.getGraphManager().registeredNodes());

I stepped through it in the debugger and it really seems to be it.

Rob

> On 20 Apr 2026, at 17:20, Andrus Adamchik <[email protected]> wrote:
>=20
> Hi Rob,
>=20
> 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=

>=20
> Andrus
>=20
>=20
>> 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
>=20