heikkilevanto / beertracker

Simple script to track the beers I drink
GNU General Public License v2.0
2 stars 1 forks source link

Cache the graph #295

Closed heikkilevanto closed 3 months ago

heikkilevanto commented 3 months ago

Most of the time we slow show the same graph again. Only two things require a new plot: changing the graph parameters, and changes in the data file.

And actually, the default graph is by far the most often used, so we may not need to cache any of the special ones. Just write the default graph in a different file than the special ones.

If requesting the default graph, check that the age of the graph is less than a few hours, and that the data file is not newer than the cached graph.

heikkilevanto commented 3 months ago

Strictly speaking, we have two default graphs, a big one and a small one. Cache both, if need be.

It may be easier to generate the png file name when plotting the graph, based on the plot file name and plot parameters. Something like heikki-2024-02-17-2024-03-18-B.png Then check if we have such file already, and if so, just use it. Before this, delete all heikki-*.png files that are too old: Older than the data file, or older than some given limit like a day.

heikkilevanto commented 3 months ago

Implemented like described above. Found that it works even better than I expected, since the browser caches the image files with dates in them, and only loads the file if it has changed server-side.