@@ -272,7 +272,7 @@ This greatly reduces the amount of work `render` needs to do on the prerendered
272272
273273#### Caching
274274You may want to cache rendered content. This is easy to do; the main thing to keep in
275- mind is you'll likely want to return a ` SafeString ` . For example, here's how you might cache locally with ` lru_cache ` :
275+ mind is you'll likely want to return a ` SafeString ` . For example, here's how you might cache with ` lru_cache ` :
276276
277277``` python
278278from simple_html import prerender, SafeString, h1
@@ -286,9 +286,9 @@ def greeting(name: str) -> SafeString:
286286 )
287287```
288288
289- One thing to keep in mind is that not all variants of ` Node ` will work as _ arguments_ to a function like the
290- one above -- i.e. ` list[Node] ` is not cacheable . Another way to use ` prerender ` in combination with a caching function
291- is to prerender arguments:
289+ One thing to remember is that not all variants of ` Node ` are hashable, and thus will work as _ arguments_ to a function
290+ where the arguments constitute the cache key -- i.e. ` list[Node] ` is not hashable . Another way to use ` prerender `
291+ in combination with a caching function is to prerender arguments:
292292
293293``` python
294294from simple_html import prerender, SafeString, h1, div, html, body, head, ul, li
@@ -306,15 +306,18 @@ def cached_content(children: SafeString) -> SafeString:
306306 )
307307 )
308308
309- def page ():
309+ def page (words_to_render : list[ str ] ):
310310 return html(
311311 head,
312312 body(
313313 cached_content(
314314 prerender(ul([
315- li(letter ) for letter in " abcdefg "
315+ li(word ) for word in words_to_render
316316 ]))
317317 )
318318 )
319319 )
320320```
321+ Keep in mind that using ` prerender ` on dynamic content -- not at the module level -- still incurs all the overhead
322+ of ` render ` each time that content is rendered, so, for this approach to make sense, the prerendered content should
323+ be a small portion of the full content of the ` cached_content ` function.
0 commit comments