I believe your first example. Here is some clarification. object2 = // something that fetches object2 -- object2 is now in the object cache object1 = object2.getObject1(); // makes a call to the database and fetches object1 -- does not put object1 in the object cache object1 = object2.getObject1(); // makes another call to the database to fetch object1, since object1 is not in the object cache
-Frank On Tue, May 17, 2016 at 2:21 PM, Michael Gentry <[email protected]> wrote: > Hi Frank, > > I'm a little confused by this part: > > "If we retrieve Object2 from the database, it is placed in the object > cache. Afterwards, if we retrieve Object1 via the getter in Object2, > Object1 is not cached. So, every time we make the request for Object1 via > the getter, another call is made to the database." > > Are you saying: > > object2 = // something that fetches object2 > object1 = object2.getObject1(); // trips fault, fetches object1 > object1 = object2.getObject1(); // trips fault, fetches object1 > > Or: > > object2 = // something that fetches object2 > object1 = object2.getObject1(); // trips fault, fetches object1 > object2 = // refetch object2 from cache > object1 = object2.getObject1(); // trips fault, fetches object1 > > Thanks, > > mrg > > > On Tue, May 17, 2016 at 9:32 AM, Frank Herrmann < > [email protected]> wrote: > > > Hello all, > > > > I have a question regarding how Cayenne does caching. Right now, if we > > retrieve an object from the database via Cayenne, it is placed in the > > object cache. However, in our experience, if we then retrieve another > > object via the relationship on the first object, it is not cached. > > > > A rough example: > > > > public class Object1 { > > ... misc attributes ... > > } > > > > public class Object2 { > > ... misc attributes... > > private Object1 object1; > > > > public Object1 getObject1() { > > return object1; > > } > > } > > > > If we retrieve Object2 from the database, it is placed in the object > cache. > > Afterwards, if we retrieve Object1 via the getter in Object2, Object1 is > > not cached. So, every time we make the request for Object1 via the > getter, > > another call is made to the database. I have fixed this for individual > > instances by using prefetches. However, our application is quite large, > and > > I don't like the idea of tracking down case. > > > > Is there some way for Cayenne to place the relationship objects into the > > object cache the first time they are retrieved? We are using EhCache for > > our query caching, so if the object cache is not an options, is there a > way > > to store these relationships in a short lived query cache? > > > > Thanks for the help. > > > > -Frank > > > > -- > > FRANK HERRMANN > > SOFTWARE ENGINEER > > > > T: 561-880-2998 x1563 > > > > E: [email protected] > > > > > > > > [image: [ Modernizing Medicine ]] <http://www.modmed.com/> > > [image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine> > > [image: > > [ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/> > > [image: > > [ YouTube ]] <http://www.youtube.com/user/modernizingmedicine> [image: [ > > Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog ]] > > <http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram ]] > > <http://instagram.com/modernizing_medicine> > > > -- FRANK HERRMANN SOFTWARE ENGINEER T: 561-880-2998 x1563 E: [email protected] [image: [ Modernizing Medicine ]] <http://www.modmed.com/> [image: [ Facebook ]] <http://www.facebook.com/modernizingmedicine> [image: [ LinkedIn ]] <http://www.linkedin.com/company/modernizing-medicine/> [image: [ YouTube ]] <http://www.youtube.com/user/modernizingmedicine> [image: [ Twitter ]] <https://twitter.com/modmed_EMA> [image: [ Blog ]] <http://www.modmed.com/BlogBeyondEMR> [image: [ Instagram ]] <http://instagram.com/modernizing_medicine>
