grape icon indicating copy to clipboard operation
grape copied to clipboard

Add support for cache in resources

Open cyppan opened this issue 8 years ago • 0 comments

I think it's better to implement caching as a dedicated feature instead of composing a DataSource.

Once the oplog and a tailable cursor has been implemented, it's pretty easy to add a long-lived memory cache which would be an atom referencing a map of $resource-$id keys to document futures. This way requests are de-deduplicated de facto. In the case of querying several ids at one time, every id can point to a future extracted from the multi-id running future.

A good simplification IMO:

  • when a query is made against ids directly, use the cache directly when possible (otherwise feed it with results).
  • when a query is made using a find specification, get the ordered ids from that query using the datasource directly, and then fetch the corresponding documents from the cache if they exists, else feed it.

cyppan avatar May 24 '16 01:05 cyppan