Caching with LiveView

I started playing around with LiveView and am comparing it to how I typically build apps (i.e. backend with graphql endpoint sends data to SPA frontend using Apollo). When I build an app with Apollo I get the benefit of data caching so that when I quickly navigate between routes the data does not need to be re-queried/re-loaded and there is no round-trip to the server. This makes for instantaneous page loads where data is already cached. Is there a relatively easy way to achieve that with LiveView? My test app is loading about 250 items into a table and there is about a second delay and flicker when navigating to the page. I’d like to cache the data for subsequent trips to that page.

4 Likes

@ryanswapp Well, there’s two sort of fundamental things going on here.

  1. there is about a second delay and flicker when navigating to the page.

This doesn’t seem strictly speaking related to live view. Live view is not and doesn’t claim to be SPA on the server. If you change pages on the browser, you’ll be establishing new connections and doing full re-renders and that’s just how it is for now.

  1. That said, if you’re dynamically changing a bunch of content within that page, nothing would stop someone from making a GraphQL client within Elixir that operates the way Apollo does and establishes caching. We’re using GraphQL internally to power server side rendered pages (regular and live) but right now that’s all just direct Absinthe.run calls. It’d be entirely possible however to build something that operates the way apollo does and uses that instead, but add some Elixir flare like handling full structs and so forth.
6 Likes