Mark Oliver's World

Posted: 20/02/2024

Caching The Contents Of This Site

This site is all stored statically (to make it completely free to host in Azure Static Web Apps), but it is generated dynamically using Blazor webassembly!

Find out more how I built this blog here

So because of that, it needs to be fast to run, and more importantly to download (webassembly means it requires the dotnet runtime downloaded, as well as the code for the site).

Once the Blazor code (dotnet runtime + site code) is downloaded, this site is all run in memory, with no further server access (ignoring assets).

So how does that work for the blog posts?

The posts themselves are markdown text files. This makes them very small, and easy to keep cached in memory.

That means, whenever we access a blog post, it's full contents are kept in RAM.

However we don't want to read all the posts if we don't have to. Therefore we access the posts markdown only ONCE no matter how many times it is accessed by the user (assuming they don't navigate away from the blog).

However there are times we need to have All the posts. This is the case when we do a search or view all blog posts.

For example, when we search, we search the title and the contents of the posts. Which means we need them all in memory to do that.

This may not be sustainable in the long term as the number of posts grow, but for a few hundred it should be fine (famous last words?).

Some quick calculations show that with the current 73 posts, they fit in 270KB (I don't keep the rendered view just the raw text), which is smaller than a lot of images floating round the web.


Thanks for reading this post.

If you want to reach out, catch me on Twitter!

I am always open to mentoring people, so get in touch.