Ind.ie is now Small Technology Foundation.
Commit 0ee31429 authored by Aral Balkan's avatar Aral Balkan

Add document caching documentation

parent c15ec06a
################################################################################
#
# Cached documents page.
#
# Demonstrates how cached documents are used.
#
# Copyright © Aral Balkan.
# Released with ♥ by Ind.ie under the MIT License.
# Portions released under the Apache License.
#
################################################################################
exports.route = (request, response) ->
data =
title: 'Ind.ie Labs: Set: Document Caching'
__set:
cache: true # Use the document cache
response.render 'document-caching', data
......@@ -40,6 +40,9 @@ createRoute '/simple'
# Partials demo
createRoute '/partials'
# Document caching
createRoute '/document-caching'
# App.net global timeline example.
createRoute '/posts'
......
<!-- include components/head.html -->
<!-- include components/labs-header.html -->
<h2>Document Caching</h2>
<p>Document caching ensures that a template/data pair is rendered once and only once for the lifetime of the Set instance.</p>
<p>Set implements several levels of caching that is automatic. These are:</p>
<ul>
<li><strong>Partials caching:</strong> partials are cached when they are first loaded to save disk access on future hits.</li>
<li><strong>Template caching:</strong> a template with partials is cached after first composition.</li>
</ul>
<p>In addition, you may optionally opt in for document caching. To do so, include the following Set directive in your data:</p>
<pre><code class='language-coffeescript'>data = {…, __set: {cache: true}}</code></pre>
<p>When you turn on document caching, any template/data pair will only be rendered on first requiest.</p>
<p>Note: it is best to use document caching on pages where the data is expected not to change often so as to avoid excessive memory usage due to the cache. A perfect use case is for mostly static / infrequently updated pages that use partials.</p>
<section id='server'>
<h2>Express 3 router (node.js)</h2>
<pre><code class='language-coffeescript'>exports.route = (request, response) ->
data =
title: 'Ind.ie Labs: Set: Cached Documents'
__set:
cache: true # Use the document cache
response.render 'cached-documents', data
</code></pre>
</section>
<script src='js/prism.js'></script>
<!-- include components/footer.html -->
</div>
</body>
</html>
......@@ -443,6 +443,7 @@
<ul>
<li><a href='./simple'>A comparison of Set, Handlebars, and Plates with static data.</a></li>
<li><a href='./partials'>Partials demo</a></li>
<li><a href='./document-caching'>Document caching</a></li>
<li><a href='./posts'>mastodon.ar.al global timeline example</a> (<a href='./posts.html'>template</a>, <a href='./posts-real-data.html'>template with real data</a>)</li>
<li><a href='./posts-client-side-updates'>mastodon.social global timeline with client‐side updates</a> using the same template.</li>
<li><a href='./profile'>mastodon.ar.al global timeline example with profiling</a> <small>Check the console for timings.</small></li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment