1

假设我正在发出一个请求,/products.json该请求返回一个包含 X 个产品的 JSON 数组。每个都可在/product/[id].json。是否可以让午睡缓存该信息而不是为每个产品发出请求?还是我必须将我的模型与其资源分开缓存?

4

1 回答 1

1

这里有一个简短的讨论:

https://github.com/bustoutsolutions/siesta/issues/156

由于 Siesta 当前存在,每个 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 问题讨论的更多背景。

于 2017-04-15T02:20:30.760 回答