You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
19 KiB
HTML
2 lines
19 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>11.1 Cache</title><link rel="stylesheet" type="text/css" href="scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="racket.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="manual-racket.css" title="default"/><script type="text/javascript" src="scribble-common.js"></script><script type="text/javascript" src="manual-racket.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="scribble-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">►</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Pollen:<span class="mywbr"> </span> the book is a program</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="Installation.html" class="tocviewlink" data-pltdoc="x">Installation</a></td></tr><tr><td align="right">2 </td><td><a href="quick-tour.html" class="tocviewlink" data-pltdoc="x">Quick tour</a></td></tr><tr><td align="right">3 </td><td><a href="Backstory.html" class="tocviewlink" data-pltdoc="x">Backstory</a></td></tr><tr><td align="right">4 </td><td><a href="big-picture.html" class="tocviewlink" data-pltdoc="x">The big picture</a></td></tr><tr><td align="right">5 </td><td><a href="first-tutorial.html" class="tocviewlink" data-pltdoc="x">First tutorial</a></td></tr><tr><td align="right">6 </td><td><a href="second-tutorial.html" class="tocviewlink" data-pltdoc="x">Second tutorial</a></td></tr><tr><td align="right">7 </td><td><a href="third-tutorial.html" class="tocviewlink" data-pltdoc="x">Third tutorial</a></td></tr><tr><td align="right">8 </td><td><a href="raco-pollen.html" class="tocviewlink" data-pltdoc="x">Using <span class="stt">raco pollen</span></a></td></tr><tr><td align="right">9 </td><td><a href="File_formats.html" class="tocviewlink" data-pltdoc="x">File formats</a></td></tr><tr><td align="right">10 </td><td><a href="reader.html" class="tocviewlink" data-pltdoc="x">◊ command overview</a></td></tr><tr><td align="right">11 </td><td><a href="Module_reference.html" class="tocviewselflink" data-pltdoc="x">Module reference</a></td></tr><tr><td align="right">12 </td><td><a href="Acknowledgments.html" class="tocviewlink" data-pltdoc="x">Acknowledgments</a></td></tr><tr><td align="right">13 </td><td><a href="License___source_code.html" class="tocviewlink" data-pltdoc="x">License & source code</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_1");">▼</a></td><td>11 </td><td><a href="Module_reference.html" class="tocviewlink" data-pltdoc="x">Module reference</a></td></tr></table><div class="tocviewsublistbottom" style="display: block;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">11.1 </td><td><a href="Cache.html" class="tocviewselflink" data-pltdoc="x">Cache</a></td></tr><tr><td align="right">11.2 </td><td><a href="Decode.html" class="tocviewlink" data-pltdoc="x">Decode</a></td></tr><tr><td align="right">11.3 </td><td><a href="file-types.html" class="tocviewlink" data-pltdoc="x">File</a></td></tr><tr><td align="right">11.4 </td><td><a href="Pagetree.html" class="tocviewlink" data-pltdoc="x">Pagetree</a></td></tr><tr><td align="right">11.5 </td><td><a href="Render.html" class="tocviewlink" data-pltdoc="x">Render</a></td></tr><tr><td align="right">11.6 </td><td><a href="Template.html" class="tocviewlink" data-pltdoc="x">Template</a></td></tr><tr><td align="right">11.7 </td><td><a href="Tag.html" class="tocviewlink" data-pltdoc="x">Tag</a></td></tr><tr><td align="right">11.8 </td><td><a href="Top.html" class="tocviewlink" data-pltdoc="x">Top</a></td></tr><tr><td align="right">11.9 </td><td><a href="World.html" class="tocviewlink" data-pltdoc="x">World</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><a href="#%28def._%28%28lib._pollen%2Fcache..rkt%29._current-cache%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym">current-<wbr></wbr>cache</span></a></td></tr><tr><td><a href="#%28def._%28%28lib._pollen%2Fcache..rkt%29._cached-require%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym">cached-<wbr></wbr>require</span></a></td></tr><tr><td><a href="#%28def._%28%28lib._pollen%2Fcache..rkt%29._make-cache%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym">make-<wbr></wbr>cache</span></a></td></tr><tr><td><a href="#%28def._%28%28lib._pollen%2Fcache..rkt%29._reset-cache%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym">reset-<wbr></wbr>cache</span></a></td></tr><tr><td><a href="#%28def._%28%28lib._pollen%2Fcache..rkt%29._cache-ref%29%29" class="tocsublink" data-pltdoc="x"><span class="RktSym">cache-<wbr></wbr>ref</span></a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="version">6.1.0.8</span></div><div class="navsettop"><span class="navleft"><div class="nosearchform"></div> </span><span class="navright"> <a href="Module_reference.html" title="backward to "11 Module reference"" data-pltdoc="x">← prev</a> <a href="Module_reference.html" title="up to "11 Module reference"" data-pltdoc="x">up</a> <a href="Decode.html" title="forward to "11.2 Decode"" data-pltdoc="x">next →</a></span> </div><h4>11.1<tt> </tt><a name="(part._.Cache)"></a><a name="(mod-path._pollen/cache)"></a>Cache</h4><p><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29" class="RktStxLink" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="Cache.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">pollen/cache</span></a><span class="RktPn">)</span></td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <span class="stt">pollen</span></span></td></tr></table></p><p>The slowest part of a <span class="RktSym"><a href="Render.html#%28def._%28%28lib._pollen%2Frender..rkt%29._render%29%29" class="RktValLink" data-pltdoc="x">render</a></span> is parsing and decoding the source file. Often, previewing a single source file necessarily means decoding others (for instance templates, or other source files that are linked into the main source file). But usually, only one source file is changing at a time. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in <span class="RktSym">doc</span><span class="RktMeta"></span> and <span class="RktSym">metas</span><span class="RktMeta"></span> — in the cache so they can be reused.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>parameter</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._pollen/cache..rkt)._current-cache))"></a><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">current-cache</span></span></span><span class="RktPn"></span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash~3f%29%29" class="RktValLink" data-pltdoc="x">hash?</a></span></p></blockquote></td></tr><tr><td><span class="RktPn">(</span><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">current-cache</span></span></span><span class="hspace"> </span><span class="RktVar">hash</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/void.html#%28def._%28%28quote._~23~25kernel%29._void~3f%29%29" class="RktValLink" data-pltdoc="x">void?</a></span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">hash</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash~3f%29%29" class="RktValLink" data-pltdoc="x">hash?</a></span></td></tr></table></blockquote></div><div class="SIntrapara">A parameter that refers to the current cache. It is initialized with <span class="RktSym">make-cache</span>.</div></p><p>The cache is a hash table that uses the complete path of a source file as its keys. The value associated with each of these keys is a subcache — another hash table with keys <span class="RktVal">'</span><span class="RktVal">doc</span>, <span class="RktVal">'</span><span class="RktVal">metas</span> (for storing the exports of the source file) and <span class="RktVal">'</span><span class="RktVal">mod-time</span> (for storing the modification time, provided by <span class="RktSym"><a href="http://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28quote._~23~25kernel%29._file-or-directory-modify-seconds%29%29" class="RktValLink" data-pltdoc="x">file-or-directory-modify-seconds</a></span>).</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._pollen/cache..rkt)._cached-require))"></a><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">cached-require</span></span></span><span class="hspace"> </span><span class="RktVar">source-path</span><span class="hspace"> </span><span class="RktVar">key</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29" class="RktValLink" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/txexpr/index.html#%28def._%28%28lib._txexpr%2Fmain..rkt%29._txexpr~3f%29%29" class="RktValLink" data-pltdoc="x">txexpr?</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash~3f%29%29" class="RktValLink" data-pltdoc="x">hash?</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/number-types.html#%28def._%28%28quote._~23~25kernel%29._integer~3f%29%29" class="RktValLink" data-pltdoc="x">integer?</a></span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">source-path</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><span class="badlink"><span class="RktValLink">pathish?</span></span></span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">key</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29" class="RktValLink" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktVal">'</span><span class="RktVal">doc</span><span class="hspace"> </span><span class="RktVal">'</span><span class="RktVal">metas</span><span class="hspace"> </span><span class="RktVal">'</span><span class="RktVal">mod-time</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Similar to <span class="RktPn">(</span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29" class="RktValLink" data-pltdoc="x">dynamic-require</a></span><span class="stt"> </span><span class="RktVar">source-path</span><span class="stt"> </span><span class="RktVar">key</span><span class="RktPn">)</span>, except that it first tries to retrieve the requested value out of <span class="RktSym">current-cache</span>. If it’s not there, or out of date, <span class="RktSym"><a href="http://docs.racket-lang.org/reference/Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29" class="RktValLink" data-pltdoc="x">dynamic-require</a></span> is used to update the value.</div></p><p>The only keys supported are <span class="RktVal">'</span><span class="RktVal">doc</span>, <span class="RktVal">'</span><span class="RktVal">metas</span>, and <span class="RktVal">'</span><span class="RktVal">mod-time</span>.</p><p>If you want the speed benefit of the cache, you should <span style="font-weight: bold">always</span> use <span class="RktSym">cached-require</span> to get data from Pollen source files. That doesn’t mean you can’t still use functions like <span class="RktSym"><a href="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29" class="RktStxLink" data-pltdoc="x">require</a></span>, <span class="RktSym"><a href="http://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._local-require%29%29" class="RktStxLink" data-pltdoc="x">local-require</a></span>, and <span class="RktSym"><a href="http://docs.racket-lang.org/reference/Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29" class="RktValLink" data-pltdoc="x">dynamic-require</a></span>. They’ll just be slower.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._pollen/cache..rkt)._make-cache))"></a><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">make-cache</span></span></span><span class="RktPn"></span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash~3f%29%29" class="RktValLink" data-pltdoc="x">hash?</a></span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Initializes <span class="RktSym">current-cache</span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._pollen/cache..rkt)._reset-cache))"></a><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">reset-cache</span></span></span><span class="RktPn"></span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/void.html#%28def._%28%28quote._~23~25kernel%29._void~3f%29%29" class="RktValLink" data-pltdoc="x">void?</a></span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Clears <span class="RktSym">current-cache</span>. When only the nuclear option will do.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._pollen/cache..rkt)._cache-ref))"></a><span title="Provided from: pollen/cache | Package: pollen"><span class="RktSym"><span class="RktSymDef RktSym">cache-ref</span></span></span><span class="hspace"> </span><span class="RktVar">source-path</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="http://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash~3f%29%29" class="RktValLink" data-pltdoc="x">hash?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">source-path</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><span class="badlink"><span class="RktValLink">pathish?</span></span></span></td></tr></table></blockquote></div><div class="SIntrapara">Returns the subcache associated with the key <span class="RktVar">source-path</span>, which will itself be a hash table. See <span class="RktSym">current-cache</span>.</div></p><div class="navsetbottom"><span class="navleft"><div class="nosearchform"></div> </span><span class="navright"> <a href="Module_reference.html" title="backward to "11 Module reference"" data-pltdoc="x">← prev</a> <a href="Module_reference.html" title="up to "11 Module reference"" data-pltdoc="x">up</a> <a href="Decode.html" title="forward to "11.2 Decode"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html> |