Skip to content Skip to sidebar Skip to footer

What Breeze Settings Are Needed To Make Caching Work?

I thought that Breeze does caching automatically, but in my simple test below it does not work. What other settings are needed to make this happen? var dataService = new breeze.Dat

Solution 1:

After reading further in the documentation I see that without metadata about the objects, Breeze will do no caching:

They will be simple JavaScript objects, not entities. Breeze won't cache them, track their changes, validate them, etc. Breeze is acting only as an HTTP retrieval mechanism and no more.

Below is an updated (working) version of my sample code:

var dataService = new breeze.DataService({
    serviceName: 'api',
    hasServerMetadata: false
});

var manager = new breeze.EntityManager({ dataService: dataService });
manager.metadataStore.addEntityType({
    shortName: "ContentType",
    namespace: "MyCompany.MyProduct.Models",
    autoGeneratedKeyType: breeze.AutoGeneratedKeyType.None,
    dataProperties: {
        Name: { dataType: breeze.DataType.String, maxLength: 30, isNullable: false, isPartOfKey: true },
        Description: { dataType: breeze.DataType.String, maxLength: 60, isNullable: false }
    }
});

//// these lines are the same as before, but now they work because of the metadata//console.log('before fetch', manager.getEntities()); // returns [] as expectedvar query = breeze.EntityQuery.from("ContentTypes");
manager.executeQuery(query).then(function(data) {
    console.log(data.results.length); // 3
    manager.addEntity(data.results[0]);
    console.log('after fetch', manager.getEntities()); // now it returns 3 entities
});

Post a Comment for "What Breeze Settings Are Needed To Make Caching Work?"