Python Library Caching
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="./">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <title>Welcome to cachings’s documentation! &#8212; caching documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
  8. <link rel="stylesheet" type="text/css" href="_static/pydoctheme.css?v=41b4f12d" />
  9. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="_static/pygments_dark.css?v=b20cc3f5" />
  10. <script src="_static/documentation_options.js?v=5929fcd5"></script>
  11. <script src="_static/doctools.js?v=9a2dae69"></script>
  12. <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
  13. <link rel="index" title="Index" href="genindex.html" />
  14. <link rel="search" title="Search" href="search.html" /><link rel="stylesheet" href="_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  15. <link rel="shortcut icon" type="image/png" href="_static/py.svg" />
  16. <script type="text/javascript" src="_static/copybutton.js"></script>
  17. <script type="text/javascript" src="_static/menu.js"></script>
  18. <script type="text/javascript" src="_static/search-focus.js"></script>
  19. <script type="text/javascript" src="_static/themetoggle.js"></script>
  20. </head>
  21. <body>
  22. <div class="mobile-nav">
  23. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  24. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  25. <nav class="nav-content" role="navigation">
  26. <label for="menuToggler" class="toggler__label">
  27. <span></span>
  28. </label>
  29. <span class="nav-items-wrapper">
  30. <a href="https://www.python.org/" class="nav-logo">
  31. <img src="_static/py.svg" alt="Python logo"/>
  32. </a>
  33. <span class="version_switcher_placeholder"></span>
  34. <form role="search" class="search" action="search.html" method="get">
  35. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  36. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  37. </svg>
  38. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  39. <input type="submit" value="Go"/>
  40. </form>
  41. </span>
  42. </nav>
  43. <div class="menu-wrapper">
  44. <nav class="menu" role="navigation" aria-label="main navigation">
  45. <div class="language_switcher_placeholder"></div>
  46. <label class="theme-selector-label">
  47. Theme
  48. <select class="theme-selector" oninput="activateTheme(this.value)">
  49. <option value="auto" selected>Auto</option>
  50. <option value="light">Light</option>
  51. <option value="dark">Dark</option>
  52. </select>
  53. </label>
  54. <div>
  55. <h3><a href="#">Table of Contents</a></h3>
  56. <ul>
  57. <li><a class="reference internal" href="#">Welcome to cachings’s documentation!</a><ul>
  58. <li><a class="reference internal" href="#caching-caching-module">caching (Caching Module)</a></li>
  59. <li><a class="reference internal" href="#caching.property_cache_json"><code class="docutils literal notranslate"><span class="pre">property_cache_json</span></code></a></li>
  60. <li><a class="reference internal" href="#caching.property_cache_pickle"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle</span></code></a><ul>
  61. <li><a class="reference internal" href="#caching.property_cache_pickle.add_source_get_keys"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.add_source_get_keys()</span></code></a></li>
  62. <li><a class="reference internal" href="#caching.property_cache_pickle.full_update"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.full_update()</span></code></a></li>
  63. <li><a class="reference internal" href="#caching.property_cache_pickle.get"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.get()</span></code></a></li>
  64. </ul>
  65. </li>
  66. </ul>
  67. </li>
  68. <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
  69. </ul>
  70. </div>
  71. <div role="note" aria-label="source link">
  72. <h3>This Page</h3>
  73. <ul class="this-page-menu">
  74. <li><a href="_sources/index.rst.txt"
  75. rel="nofollow">Show Source</a></li>
  76. </ul>
  77. </div>
  78. <search id="searchbox" style="display: none" role="search">
  79. <h3 id="searchlabel">Quick search</h3>
  80. <div class="searchformwrapper">
  81. <form class="search" action="search.html" method="get">
  82. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  83. <input type="submit" value="Go" />
  84. </form>
  85. </div>
  86. </search>
  87. <script>document.getElementById('searchbox').style.display = "block"</script>
  88. </nav>
  89. </div>
  90. </div>
  91. <div class="related" role="navigation" aria-label="Related">
  92. <h3>Navigation</h3>
  93. <ul>
  94. <li class="right" style="margin-right: 10px">
  95. <a href="genindex.html" title="General Index"
  96. accesskey="I">index</a></li>
  97. <li class="right" >
  98. <a href="py-modindex.html" title="Python Module Index"
  99. >modules</a> |</li>
  100. <li><img src="_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  101. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  102. <li class="switchers">
  103. <div class="language_switcher_placeholder"></div>
  104. <div class="version_switcher_placeholder"></div>
  105. </li>
  106. <li>
  107. <a href="#">caching documentation</a> &#187;
  108. </li>
  109. <li class="nav-item nav-item-this"><a href="">Welcome to cachings’s documentation!</a></li>
  110. <li class="right">
  111. <div class="inline-search" role="search">
  112. <form class="inline-search" action="search.html" method="get">
  113. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  114. <input type="submit" value="Go" />
  115. </form>
  116. </div>
  117. |
  118. </li>
  119. <li class="right">
  120. <label class="theme-selector-label">
  121. Theme
  122. <select class="theme-selector" oninput="activateTheme(this.value)">
  123. <option value="auto" selected>Auto</option>
  124. <option value="light">Light</option>
  125. <option value="dark">Dark</option>
  126. </select>
  127. </label> |</li>
  128. </ul>
  129. </div>
  130. <div class="document">
  131. <div class="documentwrapper">
  132. <div class="bodywrapper">
  133. <div class="body" role="main">
  134. <section id="module-caching">
  135. <span id="welcome-to-cachings-s-documentation"></span><h1>Welcome to cachings’s documentation!<a class="headerlink" href="#module-caching" title="Link to this heading">¶</a></h1>
  136. <section id="caching-caching-module">
  137. <h2>caching (Caching Module)<a class="headerlink" href="#caching-caching-module" title="Link to this heading">¶</a></h2>
  138. <p><strong>Author:</strong></p>
  139. <ul class="simple">
  140. <li><p>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</p></li>
  141. </ul>
  142. <p><strong>Description:</strong></p>
  143. <blockquote>
  144. <div><p>This Module supports functions and classes for caching e.g. properties of other instances.</p>
  145. </div></blockquote>
  146. <p><strong>Submodules:</strong></p>
  147. <ul class="simple">
  148. <li><p><a class="reference internal" href="#caching.property_cache_json" title="caching.property_cache_json"><code class="xref py py-class docutils literal notranslate"><span class="pre">caching.property_cache_json</span></code></a></p></li>
  149. <li><p><a class="reference internal" href="#caching.property_cache_pickle" title="caching.property_cache_pickle"><code class="xref py py-class docutils literal notranslate"><span class="pre">caching.property_cache_pickle</span></code></a></p></li>
  150. </ul>
  151. <p><strong>Unittest:</strong></p>
  152. <blockquote>
  153. <div><p>See also the <a class="reference download internal" download="" href="_downloads/f5f51665bfc67c10ccc039770b738067/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</p>
  154. </div></blockquote>
  155. </section>
  156. <dl class="py class">
  157. <dt class="sig sig-object py" id="caching.property_cache_json">
  158. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">caching.</span></span><span class="sig-name descname"><span class="pre">property_cache_json</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source_instance</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache_filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_all_on_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">callback_on_data_storage</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_age</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">store_on_get</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_json" title="Link to this definition">¶</a></dt>
  159. <dd><p>See also parent <a class="reference internal" href="#caching.property_cache_pickle" title="caching.property_cache_pickle"><code class="xref py py-class docutils literal notranslate"><span class="pre">property_cache_pickle</span></code></a> for detailed information.</p>
  160. <div class="admonition important">
  161. <p class="admonition-title">Important</p>
  162. <ul class="simple">
  163. <li><p>This class uses json. You should <strong>only</strong> use keys of type string!</p></li>
  164. <li><p>Unicode types are transfered to strings</p></li>
  165. </ul>
  166. <p>See limitations of json.</p>
  167. </div>
  168. <p><strong>Example:</strong></p>
  169. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  170. <span class="c1"># -*- coding: UTF-8 -*-</span>
  171. <span class="kn">import</span> <span class="nn">caching</span>
  172. <span class="kn">import</span> <span class="nn">logging</span>
  173. <span class="kn">import</span> <span class="nn">sys</span>
  174. <span class="kn">import</span> <span class="nn">time</span>
  175. <span class="k">class</span> <span class="nc">test_slow_data</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  176. <span class="n">DATA_VERSION</span> <span class="o">=</span> <span class="mf">0.1</span>
  177. <span class="n">KEY_ONE</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>
  178. <span class="n">KEY_TWO</span> <span class="o">=</span> <span class="s1">&#39;2&#39;</span>
  179. <span class="n">KEY_THREE</span> <span class="o">=</span> <span class="s1">&#39;three&#39;</span>
  180. <span class="n">KEY_FOUR</span> <span class="o">=</span> <span class="s1">&#39;four&#39;</span>
  181. <span class="n">KEY_FIVE</span> <span class="o">=</span> <span class="s1">&#39;five&#39;</span>
  182. <span class="n">KEYS</span> <span class="o">=</span> <span class="p">[</span><span class="n">KEY_ONE</span><span class="p">,</span> <span class="n">KEY_TWO</span><span class="p">,</span> <span class="n">KEY_THREE</span><span class="p">,</span> <span class="n">KEY_FOUR</span><span class="p">,</span> <span class="n">KEY_FIVE</span><span class="p">]</span>
  183. <span class="k">def</span> <span class="nf">data_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  184. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">DATA_VERSION</span>
  185. <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  186. <span class="k">try</span><span class="p">:</span>
  187. <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="sa">f</span><span class="s1">&#39;__</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">__&#39;</span><span class="p">)()</span>
  188. <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
  189. <span class="k">return</span> <span class="n">default</span>
  190. <span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  191. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEYS</span>
  192. <span class="k">def</span> <span class="nf">uid</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  193. <span class="k">return</span> <span class="kc">None</span>
  194. <span class="k">def</span> <span class="nf">print_n_sleep</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span>
  195. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;slow get executed for </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">k</span><span class="p">)</span>
  196. <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
  197. <span class="k">def</span> <span class="nf">__1__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  198. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__1__&quot;</span><span class="p">)</span>
  199. <span class="k">return</span> <span class="s1">&#39;one&#39;</span>
  200. <span class="k">def</span> <span class="nf">__2__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  201. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__2__&quot;</span><span class="p">)</span>
  202. <span class="k">return</span> <span class="s1">&#39;two&#39;</span>
  203. <span class="k">def</span> <span class="nf">__three__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  204. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__three__&quot;</span><span class="p">)</span>
  205. <span class="k">return</span> <span class="s1">&#39;three&#39;</span>
  206. <span class="k">def</span> <span class="nf">__four__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  207. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__four__&quot;</span><span class="p">)</span>
  208. <span class="k">return</span> <span class="s1">&#39;four&#39;</span>
  209. <span class="k">def</span> <span class="nf">__five__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  210. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__five__&quot;</span><span class="p">)</span>
  211. <span class="k">return</span> <span class="s1">&#39;five&#39;</span>
  212. <span class="k">class</span> <span class="nc">test_slow_data_cached</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">):</span>
  213. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
  214. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  215. <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="n">caching</span><span class="o">.</span><span class="n">property_cache_json</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">(),</span> <span class="s1">&#39;cache.json&#39;</span><span class="p">)</span>
  216. <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_THREE</span><span class="p">)</span>
  217. <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  218. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
  219. <span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
  220. <span class="c1"># Logging configuration</span>
  221. <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span>
  222. <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">%(asctime)s</span><span class="s2">: </span><span class="si">%(levelname)8s</span><span class="s2"> - </span><span class="si">%(name)s</span><span class="s2"> - </span><span class="si">%(message)s</span><span class="s2">&quot;</span><span class="p">,</span>
  223. <span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span>
  224. <span class="n">stream</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span>
  225. <span class="p">)</span>
  226. <span class="c1"># Example</span>
  227. <span class="n">tm</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
  228. <span class="n">data</span> <span class="o">=</span> <span class="n">test_slow_data_cached</span><span class="p">()</span>
  229. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Testing property_cache (json):</span><span class="se">\n</span><span class="s1">--------------------------------&#39;</span><span class="p">)</span>
  230. <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
  231. <span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
  232. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;--------------------------------</span><span class="se">\n</span><span class="s1">The execution time was </span><span class="si">%.1f</span><span class="s1">s&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">tm</span><span class="p">))</span>
  233. </pre></div>
  234. </div>
  235. <p>Will result on the first execution to the following output (with a long execution time):</p>
  236. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Testing</span> <span class="n">property_cache</span> <span class="p">(</span><span class="n">json</span><span class="p">):</span>
  237. <span class="o">--------------------------------</span>
  238. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">08</span><span class="p">,</span><span class="mi">845</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Cache</span> <span class="n">file</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">exists</span> <span class="p">(</span><span class="n">yet</span><span class="p">)</span><span class="o">.</span>
  239. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">08</span><span class="p">,</span><span class="mi">846</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  240. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">08</span><span class="p">,</span><span class="mi">846</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;1&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  241. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__1__</span>
  242. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">11</span><span class="p">,</span><span class="mi">847</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">one</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995671</span> <span class="n">to</span> <span class="n">chache</span>
  243. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">11</span><span class="p">,</span><span class="mi">847</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  244. <span class="n">one</span>
  245. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">11</span><span class="p">,</span><span class="mi">848</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;2&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  246. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__2__</span>
  247. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">849</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">two</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995674</span> <span class="n">to</span> <span class="n">chache</span>
  248. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">850</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  249. <span class="n">two</span>
  250. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">850</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Key</span> <span class="s1">&#39;three&#39;</span> <span class="ow">is</span> <span class="n">excluded</span> <span class="n">by</span> <span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">()</span><span class="o">.</span> <span class="n">Uncached</span> <span class="n">data</span> <span class="n">will</span> <span class="n">be</span> <span class="n">returned</span><span class="o">.</span>
  251. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__three__</span>
  252. <span class="n">three</span>
  253. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">17</span><span class="p">,</span><span class="mi">851</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;four&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  254. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__four__</span>
  255. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">20</span><span class="p">,</span><span class="mi">851</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="n">four</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">four</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995680</span> <span class="n">to</span> <span class="n">chache</span>
  256. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">20</span><span class="p">,</span><span class="mi">853</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  257. <span class="n">four</span>
  258. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">20</span><span class="p">,</span><span class="mi">854</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;five&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  259. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__five__</span>
  260. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">854</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="n">five</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">five</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995683</span> <span class="n">to</span> <span class="n">chache</span>
  261. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">855</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  262. <span class="n">five</span>
  263. <span class="o">--------------------------------</span>
  264. <span class="n">The</span> <span class="n">execution</span> <span class="n">time</span> <span class="n">was</span> <span class="mf">15.0</span><span class="n">s</span>
  265. </pre></div>
  266. </div>
  267. <p>With every following execution the time cosumption my by much smaller:</p>
  268. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Testing</span> <span class="n">property_cache</span> <span class="p">(</span><span class="n">json</span><span class="p">):</span>
  269. <span class="o">--------------------------------</span>
  270. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">983</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="n">properties</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
  271. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">984</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;1&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  272. <span class="n">one</span>
  273. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">984</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;2&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  274. <span class="n">two</span>
  275. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">23</span><span class="p">,</span><span class="mi">984</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Key</span> <span class="s1">&#39;three&#39;</span> <span class="ow">is</span> <span class="n">excluded</span> <span class="n">by</span> <span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">()</span><span class="o">.</span> <span class="n">Uncached</span> <span class="n">data</span> <span class="n">will</span> <span class="n">be</span> <span class="n">returned</span><span class="o">.</span>
  276. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__three__</span>
  277. <span class="n">three</span>
  278. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">26</span><span class="p">,</span><span class="mi">984</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;four&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  279. <span class="n">four</span>
  280. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">26</span><span class="p">,</span><span class="mi">985</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;five&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  281. <span class="n">five</span>
  282. <span class="o">--------------------------------</span>
  283. <span class="n">The</span> <span class="n">execution</span> <span class="n">time</span> <span class="n">was</span> <span class="mf">3.0</span><span class="n">s</span>
  284. </pre></div>
  285. </div>
  286. </dd></dl>
  287. <dl class="py class">
  288. <dt class="sig sig-object py" id="caching.property_cache_pickle">
  289. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">caching.</span></span><span class="sig-name descname"><span class="pre">property_cache_pickle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source_instance</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache_filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_all_on_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">callback_on_data_storage</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_age</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">store_on_get</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle" title="Link to this definition">¶</a></dt>
  290. <dd><p>This class caches the data from a given <cite>source_instance</cite>. It takes the data from the cache instead of generating the data from the <cite>source_instance</cite>,
  291. if the conditions for the cache usage are given.</p>
  292. <div class="admonition-required-properties-for-the-source-instance admonition">
  293. <p class="admonition-title">Required properties for the <cite>source_instance</cite></p>
  294. <ul class="simple">
  295. <li><p><strong>uid():</strong> returns the unique id of the source’s source or None, if you don’t want to use the unique id.</p></li>
  296. <li><p><strong>keys():</strong> returns a list of all available keys.</p></li>
  297. <li><p><strong>data_version():</strong> returns a version number of the current data (it should be increased, if the get method of the source instance returns improved values or the data structure had been changed).</p></li>
  298. <li><p><strong>get(key, default):</strong> returns the property for a key. If key does not exists, default will be returned.</p></li>
  299. </ul>
  300. </div>
  301. <dl class="field-list simple">
  302. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  303. <dd class="field-odd"><ul class="simple">
  304. <li><p><strong>source_instance</strong> (<em>instance</em>) – The source instance holding the data</p></li>
  305. <li><p><strong>cache_filename</strong> (<em>str</em>) – File name, where the properties are stored as cache</p></li>
  306. <li><p><strong>load_all_on_init</strong> (<em>bool</em>) – True will load all data from the source instance, when the cache will be initialised the first time.</p></li>
  307. <li><p><strong>callback_on_data_storage</strong> (<em>method</em>) – The callback will be executed every time when the cache file is stored. It will be executed with the instance of this class as first argument.</p></li>
  308. <li><p><strong>max_age</strong> (<em>int</em><em> or </em><em>None</em>) – The maximum age of the cached data in seconds or None for no maximum age.</p></li>
  309. <li><p><strong>store_on_get</strong> (<em>bool</em>) – False will prevent cache storage with execution of the <cite>.get(key, default)</cite> method. You need to store the cache somewhere else.</p></li>
  310. </ul>
  311. </dd>
  312. </dl>
  313. <div class="admonition-the-cache-will-be-used-if-all-following-conditions-are-given admonition">
  314. <p class="admonition-title">The cache will be used, if all following conditions are given</p>
  315. <ul class="simple">
  316. <li><p>The key is in the list returned by <cite>.keys()</cite> method of the <cite>source_instance</cite></p></li>
  317. <li><p>The key is not in the list of keys added by the <cite>.add_source_get_keys()</cite> method.</p></li>
  318. <li><p>The cache age is less then the given max_age parameter or the given max_age is None.</p></li>
  319. <li><p>The uid of the source instance (e.g. a checksum or unique id of the source) is identically to to uid stored in the cache.</p></li>
  320. <li><p>The data version of the <cite>source_instance</cite> is &lt;= the data version stored in the cache.</p></li>
  321. <li><p>The value is available in the previous stored information</p></li>
  322. </ul>
  323. </div>
  324. <p><strong>Example:</strong></p>
  325. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  326. <span class="c1"># -*- coding: UTF-8 -*-</span>
  327. <span class="kn">import</span> <span class="nn">caching</span>
  328. <span class="kn">import</span> <span class="nn">logging</span>
  329. <span class="kn">import</span> <span class="nn">sys</span>
  330. <span class="kn">import</span> <span class="nn">time</span>
  331. <span class="k">class</span> <span class="nc">test_slow_data</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  332. <span class="n">DATA_VERSION</span> <span class="o">=</span> <span class="mf">0.1</span>
  333. <span class="n">KEY_ONE</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>
  334. <span class="n">KEY_TWO</span> <span class="o">=</span> <span class="s1">&#39;2&#39;</span>
  335. <span class="n">KEY_THREE</span> <span class="o">=</span> <span class="s1">&#39;three&#39;</span>
  336. <span class="n">KEY_FOUR</span> <span class="o">=</span> <span class="s1">&#39;four&#39;</span>
  337. <span class="n">KEY_FIVE</span> <span class="o">=</span> <span class="s1">&#39;five&#39;</span>
  338. <span class="n">KEYS</span> <span class="o">=</span> <span class="p">[</span><span class="n">KEY_ONE</span><span class="p">,</span> <span class="n">KEY_TWO</span><span class="p">,</span> <span class="n">KEY_THREE</span><span class="p">,</span> <span class="n">KEY_FOUR</span><span class="p">,</span> <span class="n">KEY_FIVE</span><span class="p">]</span>
  339. <span class="k">def</span> <span class="nf">data_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  340. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">DATA_VERSION</span>
  341. <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  342. <span class="k">try</span><span class="p">:</span>
  343. <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="sa">f</span><span class="s1">&#39;__</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">__&#39;</span><span class="p">)()</span>
  344. <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
  345. <span class="k">return</span> <span class="n">default</span>
  346. <span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  347. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEYS</span>
  348. <span class="k">def</span> <span class="nf">uid</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  349. <span class="k">return</span> <span class="kc">None</span>
  350. <span class="k">def</span> <span class="nf">print_n_sleep</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">k</span><span class="p">):</span>
  351. <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;slow get executed for </span><span class="si">%s</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">k</span><span class="p">)</span>
  352. <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
  353. <span class="k">def</span> <span class="nf">__1__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  354. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__1__&quot;</span><span class="p">)</span>
  355. <span class="k">return</span> <span class="s1">&#39;one&#39;</span>
  356. <span class="k">def</span> <span class="nf">__2__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  357. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__2__&quot;</span><span class="p">)</span>
  358. <span class="k">return</span> <span class="s1">&#39;two&#39;</span>
  359. <span class="k">def</span> <span class="nf">__three__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  360. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__three__&quot;</span><span class="p">)</span>
  361. <span class="k">return</span> <span class="s1">&#39;three&#39;</span>
  362. <span class="k">def</span> <span class="nf">__four__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  363. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__four__&quot;</span><span class="p">)</span>
  364. <span class="k">return</span> <span class="s1">&#39;four&#39;</span>
  365. <span class="k">def</span> <span class="nf">__five__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  366. <span class="bp">self</span><span class="o">.</span><span class="n">print_n_sleep</span><span class="p">(</span><span class="s2">&quot;__five__&quot;</span><span class="p">)</span>
  367. <span class="k">return</span> <span class="s1">&#39;five&#39;</span>
  368. <span class="k">class</span> <span class="nc">test_slow_data_cached</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">):</span>
  369. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
  370. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  371. <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="n">caching</span><span class="o">.</span><span class="n">property_cache_json</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">(),</span> <span class="s1">&#39;cache.pickle&#39;</span><span class="p">)</span>
  372. <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">KEY_THREE</span><span class="p">)</span>
  373. <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
  374. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
  375. <span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
  376. <span class="c1"># Logging configuration</span>
  377. <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span>
  378. <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">%(asctime)s</span><span class="s2">: </span><span class="si">%(levelname)8s</span><span class="s2"> - </span><span class="si">%(name)s</span><span class="s2"> - </span><span class="si">%(message)s</span><span class="s2">&quot;</span><span class="p">,</span>
  379. <span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span>
  380. <span class="n">stream</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span>
  381. <span class="p">)</span>
  382. <span class="c1"># Example</span>
  383. <span class="n">tm</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
  384. <span class="n">data</span> <span class="o">=</span> <span class="n">test_slow_data_cached</span><span class="p">()</span>
  385. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Testing property_cache (pickle):</span><span class="se">\n</span><span class="s1">--------------------------------&#39;</span><span class="p">)</span>
  386. <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
  387. <span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
  388. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;--------------------------------</span><span class="se">\n</span><span class="s1">The execution time was </span><span class="si">%.1f</span><span class="s1">s&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">tm</span><span class="p">))</span>
  389. </pre></div>
  390. </div>
  391. <p>Will result on the first execution to the following output (with a long execution time):</p>
  392. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Testing</span> <span class="n">property_cache</span> <span class="p">(</span><span class="n">pickle</span><span class="p">):</span>
  393. <span class="o">--------------------------------</span>
  394. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">126</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Cache</span> <span class="n">file</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">exists</span> <span class="p">(</span><span class="n">yet</span><span class="p">)</span><span class="o">.</span>
  395. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">127</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  396. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">127</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;1&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  397. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__1__</span>
  398. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">128</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">one</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995690</span> <span class="n">to</span> <span class="n">chache</span>
  399. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">129</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  400. <span class="n">one</span>
  401. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">129</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;2&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  402. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__2__</span>
  403. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">33</span><span class="p">,</span><span class="mi">130</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">two</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995693</span> <span class="n">to</span> <span class="n">chache</span>
  404. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">33</span><span class="p">,</span><span class="mi">131</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  405. <span class="n">two</span>
  406. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">33</span><span class="p">,</span><span class="mi">132</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Key</span> <span class="s1">&#39;three&#39;</span> <span class="ow">is</span> <span class="n">excluded</span> <span class="n">by</span> <span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">()</span><span class="o">.</span> <span class="n">Uncached</span> <span class="n">data</span> <span class="n">will</span> <span class="n">be</span> <span class="n">returned</span><span class="o">.</span>
  407. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__three__</span>
  408. <span class="n">three</span>
  409. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">,</span><span class="mi">133</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;four&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  410. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__four__</span>
  411. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">134</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="n">four</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">four</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995699</span> <span class="n">to</span> <span class="n">chache</span>
  412. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">135</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  413. <span class="n">four</span>
  414. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">136</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="n">key</span><span class="o">=</span><span class="s1">&#39;five&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span>
  415. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__five__</span>
  416. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">136</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Adding</span> <span class="n">key</span><span class="o">=</span><span class="n">five</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">five</span> <span class="k">with</span> <span class="n">timestamp</span><span class="o">=</span><span class="mi">1726995702</span> <span class="n">to</span> <span class="n">chache</span>
  417. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">137</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">cache</span><span class="o">-</span><span class="n">file</span> <span class="n">stored</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  418. <span class="n">five</span>
  419. <span class="o">--------------------------------</span>
  420. <span class="n">The</span> <span class="n">execution</span> <span class="n">time</span> <span class="n">was</span> <span class="mf">15.0</span><span class="n">s</span>
  421. </pre></div>
  422. </div>
  423. <p>With every following execution the time cosumption my by much smaller:</p>
  424. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Testing</span> <span class="n">property_cache</span> <span class="p">(</span><span class="n">pickle</span><span class="p">):</span>
  425. <span class="o">--------------------------------</span>
  426. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">204</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Loading</span> <span class="n">properties</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="n">cache</span><span class="o">.</span><span class="n">pickle</span><span class="p">)</span>
  427. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">204</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;1&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  428. <span class="n">one</span>
  429. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">205</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;2&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  430. <span class="n">two</span>
  431. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">205</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Key</span> <span class="s1">&#39;three&#39;</span> <span class="ow">is</span> <span class="n">excluded</span> <span class="n">by</span> <span class="o">.</span><span class="n">add_source_get_keys</span><span class="p">()</span><span class="o">.</span> <span class="n">Uncached</span> <span class="n">data</span> <span class="n">will</span> <span class="n">be</span> <span class="n">returned</span><span class="o">.</span>
  432. <span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__three__</span>
  433. <span class="n">three</span>
  434. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">205</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;four&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  435. <span class="n">four</span>
  436. <span class="mi">2024</span><span class="o">-</span><span class="mi">09</span><span class="o">-</span><span class="mi">22</span> <span class="mi">11</span><span class="p">:</span><span class="mi">01</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">206</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">caching</span> <span class="o">-</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;five&#39;</span> <span class="kn">from</span> <span class="nn">cache</span>
  437. <span class="n">five</span>
  438. <span class="o">--------------------------------</span>
  439. <span class="n">The</span> <span class="n">execution</span> <span class="n">time</span> <span class="n">was</span> <span class="mf">3.0</span><span class="n">s</span>
  440. </pre></div>
  441. </div>
  442. <dl class="py method">
  443. <dt class="sig sig-object py" id="caching.property_cache_pickle.add_source_get_keys">
  444. <span class="sig-name descname"><span class="pre">add_source_get_keys</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">keys</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle.add_source_get_keys" title="Link to this definition">¶</a></dt>
  445. <dd><p>This will add one or more keys to a list of keys which will always be provided by the <cite>source_instance</cite> instead of the cache.</p>
  446. <dl class="field-list simple">
  447. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  448. <dd class="field-odd"><p><strong>keys</strong> (<em>list</em><em>, </em><em>tuple</em><em>, </em><em>str</em>) – The key or keys to be added</p>
  449. </dd>
  450. </dl>
  451. </dd></dl>
  452. <dl class="py method">
  453. <dt class="sig sig-object py" id="caching.property_cache_pickle.full_update">
  454. <span class="sig-name descname"><span class="pre">full_update</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sleep_between_keys</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle.full_update" title="Link to this definition">¶</a></dt>
  455. <dd><p>With the execution of this method, the complete source data which needs to be cached, will be read from the source instance
  456. and the resulting cache will be stored to the given file.</p>
  457. <dl class="field-list simple">
  458. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  459. <dd class="field-odd"><p><strong>sleep_between_keys</strong> (<em>float</em><em>, </em><em>int</em>) – Time to sleep between each source data generation</p>
  460. </dd>
  461. </dl>
  462. <div class="admonition hint">
  463. <p class="admonition-title">Hint</p>
  464. <p>Use this method, if you initiallised the class with <cite>store_on_get=False</cite></p>
  465. </div>
  466. </dd></dl>
  467. <dl class="py method">
  468. <dt class="sig sig-object py" id="caching.property_cache_pickle.get">
  469. <span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle.get" title="Link to this definition">¶</a></dt>
  470. <dd><p>Method to get the cached property. If the key does not exists in the cache or <cite>source_instance</cite>, <cite>default</cite> will be returned.</p>
  471. <dl class="field-list simple">
  472. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  473. <dd class="field-odd"><ul class="simple">
  474. <li><p><strong>key</strong> – key for value to get.</p></li>
  475. <li><p><strong>default</strong> – value to be returned, if key does not exists.</p></li>
  476. </ul>
  477. </dd>
  478. <dt class="field-even">Returns<span class="colon">:</span></dt>
  479. <dd class="field-even"><p>value for a given key or default value.</p>
  480. </dd>
  481. </dl>
  482. </dd></dl>
  483. </dd></dl>
  484. <div class="toctree-wrapper compound">
  485. </div>
  486. </section>
  487. <section id="indices-and-tables">
  488. <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Link to this heading">¶</a></h1>
  489. <ul class="simple">
  490. <li><p><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></p></li>
  491. <li><p><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></p></li>
  492. <li><p><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></p></li>
  493. </ul>
  494. </section>
  495. <div class="clearer"></div>
  496. </div>
  497. </div>
  498. </div>
  499. <div class="sphinxsidebar" role="navigation" aria-label="Main">
  500. <div class="sphinxsidebarwrapper">
  501. <div>
  502. <h3><a href="#">Table of Contents</a></h3>
  503. <ul>
  504. <li><a class="reference internal" href="#">Welcome to cachings’s documentation!</a><ul>
  505. <li><a class="reference internal" href="#caching-caching-module">caching (Caching Module)</a></li>
  506. <li><a class="reference internal" href="#caching.property_cache_json"><code class="docutils literal notranslate"><span class="pre">property_cache_json</span></code></a></li>
  507. <li><a class="reference internal" href="#caching.property_cache_pickle"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle</span></code></a><ul>
  508. <li><a class="reference internal" href="#caching.property_cache_pickle.add_source_get_keys"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.add_source_get_keys()</span></code></a></li>
  509. <li><a class="reference internal" href="#caching.property_cache_pickle.full_update"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.full_update()</span></code></a></li>
  510. <li><a class="reference internal" href="#caching.property_cache_pickle.get"><code class="docutils literal notranslate"><span class="pre">property_cache_pickle.get()</span></code></a></li>
  511. </ul>
  512. </li>
  513. </ul>
  514. </li>
  515. <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
  516. </ul>
  517. </div>
  518. <div role="note" aria-label="source link">
  519. <h3>This Page</h3>
  520. <ul class="this-page-menu">
  521. <li><a href="_sources/index.rst.txt"
  522. rel="nofollow">Show Source</a></li>
  523. </ul>
  524. </div>
  525. <search id="searchbox" style="display: none" role="search">
  526. <h3 id="searchlabel">Quick search</h3>
  527. <div class="searchformwrapper">
  528. <form class="search" action="search.html" method="get">
  529. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  530. <input type="submit" value="Go" />
  531. </form>
  532. </div>
  533. </search>
  534. <script>document.getElementById('searchbox').style.display = "block"</script>
  535. </div>
  536. </div>
  537. <div class="clearer"></div>
  538. </div>
  539. <div class="related" role="navigation" aria-label="Related">
  540. <h3>Navigation</h3>
  541. <ul>
  542. <li class="right" style="margin-right: 10px">
  543. <a href="genindex.html" title="General Index"
  544. >index</a></li>
  545. <li class="right" >
  546. <a href="py-modindex.html" title="Python Module Index"
  547. >modules</a> |</li>
  548. <li><img src="_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  549. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  550. <li class="switchers">
  551. <div class="language_switcher_placeholder"></div>
  552. <div class="version_switcher_placeholder"></div>
  553. </li>
  554. <li>
  555. <a href="#">caching documentation</a> &#187;
  556. </li>
  557. <li class="nav-item nav-item-this"><a href="">Welcome to cachings’s documentation!</a></li>
  558. <li class="right">
  559. <div class="inline-search" role="search">
  560. <form class="inline-search" action="search.html" method="get">
  561. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  562. <input type="submit" value="Go" />
  563. </form>
  564. </div>
  565. |
  566. </li>
  567. <li class="right">
  568. <label class="theme-selector-label">
  569. Theme
  570. <select class="theme-selector" oninput="activateTheme(this.value)">
  571. <option value="auto" selected>Auto</option>
  572. <option value="light">Light</option>
  573. <option value="dark">Dark</option>
  574. </select>
  575. </label> |</li>
  576. </ul>
  577. </div>
  578. <div class="footer">
  579. &copy;
  580. Copyright
  581. 2021, Dirk Alders.
  582. <br />
  583. This page is licensed under the Python Software Foundation License Version 2.
  584. <br />
  585. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  586. <br />
  587. <br />
  588. The Python Software Foundation is a non-profit corporation.
  589. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  590. <br />
  591. <br />
  592. <br />
  593. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.0.2.
  594. </div>
  595. </body>
  596. </html>