1

Im having a problem where breeze always goes to the server even though I've specified FetchStrategy.FromLocalCache. I created a test script below. Th initial query goes remote as as expected. The second query also goes remote(FetchStrategy.FromLocalCache). The third query(ExecuteQueryLocally) goes to local cache. From developer tools I can see there are 2 network requests (not including metadata). What am I doing wrong?

   getCategories = function (observable) {
       var query = breeze.EntityQuery
            .from("Categories")
            .orderBy('Order');
       manager.executeQuery(query) //goes remote
           .then(fetchSucceeded)
           .fail(queryFailed);

       function fetchSucceeded(data) {
       //    observable(data.results);
           getCategoriesLocal(observable); 
       }
   },

   getCategoriesLocal = function (observable) {
       var query = breeze.EntityQuery
            .from("Categories")
            .orderBy('Order');
       query.using(breeze.FetchStrategy.FromLocalCache);
       manager.executeQuery(query)   //also goes remote
           .then(fetchSucceeded)
           .fail(queryFailed);

       function fetchSucceeded(data) {
           d = manager.executeQueryLocally(query); //goes local
           observable(d);
           return;
       }
   },
user1068557
  • 309
  • 2
  • 8

1 Answers1

0

Instead of

query.using(breeze.FetchStrategy.FromLocalCache);

you need to reassign it, i.e.

query = query.using(breeze.FetchStrategy.FromLocalCache);

In breeze all EntityQueries are immutable which means that any time you apply a change to an EntityQuery you get new one. This is by design, so that no query can get changed under you by a later modification.

Alternatively you can simply use

  manager.executeQuery(query.using(breeze.FetchStrategy.FromLocalCache));
Jay Traband
  • 17,053
  • 1
  • 23
  • 44