> On 25 Jan 2017, at 22:39 , Alejandro Infante <alejandroinfant...@gmail.com> > wrote: > > Cool! Thanks for the answers! > > Norbert mentions something interesting about references. > I have found that even though on each query mongo get the up-to-date version > of the objects, it does not install the proxies to look for the up-to-date > versions of the references of the queried object. > > I made the following experiment: > Having two images 1 and 2 and two classes A and B, each of them having one > instance variable. > ————————— > Image 1 (Create two objects, “a” referencing “b”) > [ |a b| > a := A new. > b := B new > a setInstVar: b. > b setInstVar: ‘foo'. > b save. > a save. > ] > > Image 2 (Mutates the second object, but the first is not changed) > [ > b := (repository selectAll: A) first instVar. > b setInstVar: ‘bar’. > b save. > ] > > Image 1 (Query the first object and access to the referenced object) > [ > b := (repository selectAll: A) first instVar. > b instVar. “-> foo” > b := (repository selectAll: B) first. > b instVar. “-> bar" > ] > > This little experiment showed me that I cannot trust on the state of other > objects that I have not explicitly queried for. > > Is there any way of solving this without creating new instances of voyage > repositories for each request? > > Thanks! > Alejandro
Three, actually ;) - Accept that an image will contain some stale values, and deal with conflicts at save time. This is the most performant/scalable. - Always save only root objects More overhead since there's more likeliness of cache misses and actual reloads, but you can be sure any query will return the freshest value. - Extend retrieveObjectOf:json: to either replace doc refs with proxies, or do eager (recursive) lookup of whether cached versions of referenced documents are up-to-date when returning a cached object. In reality, only the first really makes sense; as you can never guarantee how long a queried object stays current. Cheers, Henry