January 2019
Intermediate to advanced
520 pages
14h 32m
English
We will use a cache to store rendered template and returns it as a response for future requests. Ideally, the cache should have a lifetime, because if the cache is not updated, then clients won't see any updates on the page. But for our demo application, we won't reset the cache to make sure it works, because our small microservice renders a time and we can see if it's frozen. Now we will add a new field to the State struct to keep a rendered template for future responses:
cached: Arc<RwLock<Option<String>>>
We will use RwLock because we have to update this value at least once, but for values that won't be updated and can be initialized, we can use the String type without any wrapper for protection from concurrent access, such as ...
Read now
Unlock full access