How does Falcor cache data in the server side?

399 views Asked by At

I understand that in the falcor client side, it caches data in the model. On the application server side, we need to implement falcor routes as data source. Does Falcor cache data in the application server side? If so, how? Thanks,

1

There are 1 answers

0
James Conkling On

In short, no, the falcor-router does not cache data. Because a single request might be resolved by multiple routes, the router does build a per-request cache, but that cache is dropped after the router finishes responding to the request.

E.g. the following request

method=get
paths=[
  items[0..10]['id', 'name'],
  items.length,
]

could be resolved by two or three different routes, e.g.

[items[{range}]]
[items.length]
[itemsById[{keys}]

The router will merge each route response into a graph fragment until it resolves all requested paths and follows up any returned ref nodes. This graph fragment can be thought of as a per-request cache (or at least, it's referred to as such in the source code), but it is dropped after the response is returned to the client.

This implies a few things:

  • the server has no knowledge of what data is/isn't already on a client
  • graph fragments are not materialized, meaning running the same query twice (assuming it doesn't hit your falcor client model's cache) will run the same query.

Server-side caching and cache invalidation is more appropriately handled in a database layer, rather than the router layer