jamesplease / orbit-examples

Examples showing common use cases for Orbit.js
MIT License
1 stars 0 forks source link

Example configuration: memory + rest source #3

Open jamesplease opened 9 years ago

jamesplease commented 9 years ago

I think a common use case for Orbit will be using the memory source in conjunction with the rest source. A rest source, for newcomers to Orbit, is typically an API that returns data.

The behavior is as follows:

  1. Requests are always made against the memory source
  2. The memory source defers to the rest source when a value is not found
  3. Values returned by the rest source are cached in the memory source
  4. Subsequent requests for the same resource will use the cached value

This example should also explore cache invalidation. Two common invalidation strategies I've seen are:

  1. automatic invalidation based on time (resources are re-requested after, say, 5 minutes have passed)
  2. order invalidation at the time of the request. In pseudocode: store.find('author', null, {cache: false});