Implementation

Design

At a request, the server first checks, if a note is already rendered and is present in the LRU cache.
(a) If yes, it return the rendered HTML code and increases the views counter.
(b) Otherwise, the note is retrieved from the DB, rendered and put into the LRU cache; the views counter will be increased.

The rendering of note pages: there are HTML file tempates with placeholders, which will be trivially filled with replacements.

The LRU cache holds the rendered HTML for the most popular notes, which makes their access a static O(1) operation without any DB I/O.

The server keeps corresponding models for all notes in the cache for statistics updates. These models are persisted every 5 minutes to the DB.