缓存来自单个请求的多个资源
问题描述:
假设我正在请求/products.json
,它返回一个包含X个产品的JSON数组。每个都可在/product/[id].json
。是否有可能让午睡缓存该信息而不是对每个产品提出请求?还是必须将我的模型与资源分开存放?缓存来自单个请求的多个资源
答
有这种这里简短的讨论:
https://github.com/bustoutsolutions/siesta/issues/156
由于午睡目前存在的,每一个URL是一个单独的缓存状态单独的资源。但是,您可以手动传播从索引/表/搜索资源到相应的资源的变化对其个人成绩:
childResource.addObserver(self)
parentResource.addObserver(owner: self) {
if case .newData = $1 {
childResource.invalidate()
// Delayed refresh prevents redundant load if multiple
// children trigger a refresh on the same parent
DispatchQueue.main.async {
childResource.loadIfNeeded()
}
}
}
,对于更多的背景下,Github的问题的讨论。