gpt4 book ai didi

javascript - 需要什么样的 Breeze 设置才能使缓存工作?

转载 作者:行者123 更新时间:2023-11-30 17:39:51 25 4
gpt4 key购买 nike

我认为 Breeze 会自动缓存,但在我下面的简单测试中它不起作用。还需要哪些其他设置才能做到这一点?

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

var manager = new breeze.EntityManager({ dataService: dataService });
var metadataStore = manager.metadataStore;

console.log('before fetch', manager.getEntities());// returns [] as expected

var query = breeze.EntityQuery.from("ContentTypes");
manager.executeQuery(query).then(function(data) {
console.log(data.results.length); // 3
console.log('after fetch', manager.getEntities()); // still []. why???
});

最佳答案

在进一步阅读文档后,我发现没有关于对象的元数据,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.

下面是我的示例代码的更新(工作)版本:

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 expected

var 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
});

关于javascript - 需要什么样的 Breeze 设置才能使缓存工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21323736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com