JuliaPluto / PlutoSliderServer.jl

Web server to run just the `@bind` parts of a Pluto.jl notebook
https://computationalthinking.mit.edu/
The Unlicense
135 stars 18 forks source link

Non-updating plots unless git directory changes #120

Closed stefanjwojcik closed 1 year ago

stefanjwojcik commented 1 year ago

Hello!

Thanks for all the hard work the Pluto team has put into this.

I don't have a MWE, but this is something I've observed for weeks now on a personal server. I have a PlutoSliderServer running on a virtual machine. Based on a cronjob, the virtual machine recomputes some data every 24 hours, restarts the SliderServer, shows a table of data, and (in theory) plots the results.

The data table shows up as normal, however, unless you open the page in an incognito window, commit a git change, or manually delete browser data, the plots and UI functions are NOT updated.

I tried adding a @bind go button("RECOMPUTE"), but this had no effect. The only way that the UI faithfully updates is if I commit some change to the directory.

Is there a function which forces a full refresh of the underlying browser data, similar to when a git directory change is detected?

ctrekker commented 1 year ago

If I understand correctly, your notebooks running on SliderServer aren't changing, but the data they are displaying / processing is changing every 24 hours.

This would explain why the cache is giving old data, since PlutoSliderServer caches very aggresively (the max cache length is 10 years) under the assumption that if the notebook doesn't change, nor will its outputs.

There are two workarounds I know of, but neither are ideal:

  1. Open developer tools and clear the page cache manually every day (this page shows how to do this in most browsers)
  2. Add a space or newline to the end of your Pluto.jl notebooks every day in your cronjob. This will update the hashes of the notebook files and force requests to be made to a different url than yesterday, but will make git updates more annoying since the changes would be tracked

PlutoSliderServer.jl change - make cache Max-Age configurable

This option involves changes to PlutoSliderServer, which I would be happy to write since I've run into the same kinds of issues with the browser cache. The browser cache max age could be made configurable so that when the underlying data is mutated but the notebook isn't, problems like these can be solved without ugly workarounds.

@fonsp What do you think about making Max-Age configurable?

ctrekker commented 1 year ago

I opened a PR that addresses this issue. Once it get merged, the following should fix the caching issues by reducing the maximum cache age to a much lower value.

122

PlutoSliderServer.run_directory(
    "<export directory>",
    SliderServer_enabled=true,
    SliderServer_cache_max_age=60,  # only keep browser cache files for 60 seconds
    # ...additional config...
)

Edit: see fons' comment for updated solution

stefanjwojcik commented 1 year ago

Yes, I believe you nailed the details exactly - the notebook code itself remains largely static from day to day, but the underlying data change.

I think this use case is common when folks who are generating dashboards where underlying data update at some cadence. I'll try these workarounds until the PR gets merged.

Thanks for your help!

fonsp commented 1 year ago

Hey @stefanjwojcik !

We went with a slightly different solution, where you can override the value of the Cache-Control header directly:

See

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

https://github.com/JuliaPluto/PlutoSliderServer.jl/pull/122/files

Example config to disable caching:


PlutoSliderServer.run_directory(
    "<export directory>",
    SliderServer_enabled=true,
    SliderServer_cache_control="no-store, no-cache",  # no caching
    # ...additional config...
)

You can also set it to 60 seconds, etc, you have full control!

stefanjwojcik commented 1 year ago

Thanks so much for making this change Pluto Team! This is awesome.