1

Let's say I'm making a request for /products.json which returns a JSON array with X number of products. Each is available at /product/[id].json. Is it possible to make siesta cache that information instead of making a request for each product? Or do I have to cache my models separate from their resources?

Mark Lilback
  • 1,154
  • 9
  • 21

1 Answers1

1

There’s a short discussion of this here:

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

As Siesta currently exists, each URL is a separate resource with a separate cached state. However, you can manually propagate changes from an index/list/search resource to the corresponding resources for its individual results:

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()
    }
  }
}

That that Github issue discussion for more background.

Paul Cantrell
  • 9,175
  • 2
  • 40
  • 48