caching/_docs_/index.html

596 строки
63 KiB
HTML
Исходник Ответственный История

Этот файл содержит неоднозначные символы Юникода

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html class="writer-html4" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to cachingss documentation! &mdash; caching documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="#" class="icon icon-home" alt="Documentation Home"> caching
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<!-- Local TOC -->
<div class="local-toc"><ul>
<li><a class="reference internal" href="#">Welcome to cachingss documentation!</a><ul>
<li><a class="reference internal" href="#caching-caching-module">caching (Caching Module)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>
</div>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="#">caching</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="#" class="icon icon-home"></a> &raquo;</li>
<li>Welcome to cachingss documentation!</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="module-caching">
<span id="welcome-to-cachings-s-documentation"></span><h1>Welcome to cachingss documentation!<a class="headerlink" href="#module-caching" title="Permalink to this headline"></a></h1>
<div class="section" id="caching-caching-module">
<h2>caching (Caching Module)<a class="headerlink" href="#caching-caching-module" title="Permalink to this headline"></a></h2>
<p><strong>Author:</strong></p>
<ul class="simple">
<li>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;</li>
</ul>
<p><strong>Description:</strong></p>
<blockquote>
<div>This Module supports functions and classes for caching e.g. properties of other instances.</div></blockquote>
<p><strong>Submodules:</strong></p>
<ul class="simple">
<li><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></li>
<li><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></li>
</ul>
<p><strong>Unittest:</strong></p>
<blockquote>
<div>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.</div></blockquote>
<dl class="class">
<dt id="caching.property_cache_json">
<em class="property">class </em><code class="descclassname">caching.</code><code class="descname">property_cache_json</code><span class="sig-paren">(</span><em>source_instance</em>, <em>cache_filename</em>, <em>load_all_on_init=False</em>, <em>callback_on_data_storage=None</em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_json" title="Permalink to this definition"></a></dt>
<dd><p>Class to cache properties, which take longer on initialising than reading a file in json format. 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></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>source_instance</strong> (<em>instance</em>) – The source instance holding the data</li>
<li><strong>cache_filename</strong> (<em>str</em>) – File name, where the properties are stored as cache</li>
<li><strong>load_all_on_init</strong> – Optionally init behaviour control parameter. True will load all available properties from source on init, False not.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<ul class="last simple">
<li>This class uses json. You should <strong>only</strong> use keys of type string!</li>
<li>Unicode types are transfered to strings</li>
</ul>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>source_instance needs to have at least the following methods: uid(), keys(), data_version(), get()</p>
<ul class="last simple">
<li>uid(): returns the unique id of the source.</li>
<li>keys(): returns a list of all available keys.</li>
<li>data_version(): 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).</li>
<li>get(key, default): returns the property for a key. If key does not exists, default will be returned.</li>
</ul>
</div>
<p>Reasons for updating the complete data set:</p>
<ul class="simple">
<li>UID of source_instance has changed (in comparison to the cached value).</li>
<li>data_version is increased</li>
</ul>
<p><strong>Example:</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: UTF-8 -*-</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../..&#39;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">caching</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
<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>
<span class="n">_ONE</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>
<span class="n">_TWO</span> <span class="o">=</span> <span class="s1">&#39;2&#39;</span>
<span class="n">_THREE</span> <span class="o">=</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span>
<span class="n">_FOUR</span> <span class="o">=</span> <span class="s1">&#39;_property_cache_uid_&#39;</span>
<span class="n">_FIVE</span> <span class="o">=</span> <span class="s1">&#39;__property_cache_uid_&#39;</span>
<span class="n">KEYS</span> <span class="o">=</span> <span class="p">[</span><span class="n">_ONE</span><span class="p">,</span> <span class="n">_TWO</span><span class="p">,</span> <span class="n">_THREE</span><span class="p">,</span> <span class="n">_FOUR</span><span class="p">,</span> <span class="n">_FIVE</span><span class="p">]</span>
<span class="n">VERS</span> <span class="o">=</span> <span class="mf">0.1</span>
<span class="k">def</span> <span class="nf">data_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">VERS</span>
<span class="k">def</span> <span class="nf">one</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ONE</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">three</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_THREE</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">four</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_FOUR</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">five</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_FIVE</span><span class="p">)</span>
<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>
<span class="k">def</span> <span class="nf">print_n_sleep</span><span class="p">(</span><span class="n">k</span><span class="p">):</span>
<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>
<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>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ONE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;one&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;two&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_THREE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;three&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FOUR</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;four&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FIVE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;five&#39;</span>
<span class="k">return</span> <span class="n">default</span>
<span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEYS</span>
<span class="k">def</span> <span class="nf">uid</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">class</span> <span class="nc">tsd_cache_json</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__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="n">test_slow_data</span><span class="o">.</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="bp">self</span><span class="o">.</span><span class="n">_cached_data</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="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="s1">&#39;cache.json&#39;</span><span class="p">,</span> <span class="n">load_all_on_init</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">test_slow_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">)</span>
<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>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cached_data</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>
<span class="n">data</span> <span class="o">=</span> <span class="n">tsd_cache_json</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Testing property_cache (json):</span><span class="se">\\</span><span class="s1">n--------------------------------&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">one</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">two</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">three</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">four</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">five</span><span class="p">())</span>
</pre></div>
</div>
<p>Will result on the first execution to the following output (with a long execution time):</p>
<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>\<span class="n">n</span><span class="o">--------------------------------</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">282</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">283</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">1</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">48</span><span class="p">,</span><span class="mi">285</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Loading</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">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;one&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">48</span><span class="p">,</span><span class="mi">286</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="n">one</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">2</span>
<span class="n">two</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">_property_cache_data_version_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">292</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;three&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">293</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="n">three</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">_property_cache_uid_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">57</span><span class="p">,</span><span class="mi">297</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;four&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">57</span><span class="p">,</span><span class="mi">297</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="n">four</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__property_cache_uid_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">00</span><span class="p">,</span><span class="mi">301</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;__property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;five&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">00</span><span class="p">,</span><span class="mi">301</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="n">five</span>
</pre></div>
</div>
<p>With every following execution (slow for getting “two” which is not cached - see implementation):</p>
<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>\<span class="n">n</span><span class="o">--------------------------------</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">00</span><span class="p">,</span><span class="mi">380</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">00</span><span class="p">,</span><span class="mi">380</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</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> <span class="p">(</span><span class="s1">&#39;one&#39;</span><span class="p">)</span>
<span class="n">one</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">2</span>
<span class="n">two</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">03</span><span class="p">,</span><span class="mi">381</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;three&#39;</span><span class="p">)</span>
<span class="n">three</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">03</span><span class="p">,</span><span class="mi">381</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;four&#39;</span><span class="p">)</span>
<span class="n">four</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">51</span><span class="p">:</span><span class="mi">03</span><span class="p">,</span><span class="mi">381</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">JsonCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;__property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;five&#39;</span><span class="p">)</span>
<span class="n">five</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="caching.property_cache_pickle">
<em class="property">class </em><code class="descclassname">caching.</code><code class="descname">property_cache_pickle</code><span class="sig-paren">(</span><em>source_instance</em>, <em>cache_filename</em>, <em>load_all_on_init=False</em>, <em>callback_on_data_storage=None</em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle" title="Permalink to this definition"></a></dt>
<dd><p>Class to cache properties, which take longer on initialising than reading a file in pickle format.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>source_instance</strong> (<em>instance</em>) – The source instance holding the data</li>
<li><strong>cache_filename</strong> (<em>str</em>) – File name, where the properties are stored as cache</li>
<li><strong>load_all_on_init</strong> – Optionally init behaviour control parameter. True will load all available properties from source on init, False not.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>source_instance needs to have at least the following methods: uid(), keys(), data_version(), get()</p>
<ul class="last simple">
<li>uid(): returns the unique id of the source.</li>
<li>keys(): returns a list of all available keys.</li>
<li>data_version(): 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).</li>
<li>get(key, default): returns the property for a key. If key does not exists, default will be returned.</li>
</ul>
</div>
<p>Reasons for updating the complete data set:</p>
<ul class="simple">
<li>UID of source_instance has changed (in comparison to the cached value).</li>
<li>data_version is increased</li>
</ul>
<p><strong>Example:</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: UTF-8 -*-</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../..&#39;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">caching</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
<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>
<span class="n">_ONE</span> <span class="o">=</span> <span class="s1">&#39;1&#39;</span>
<span class="n">_TWO</span> <span class="o">=</span> <span class="s1">&#39;2&#39;</span>
<span class="n">_THREE</span> <span class="o">=</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span>
<span class="n">_FOUR</span> <span class="o">=</span> <span class="s1">&#39;_property_cache_uid_&#39;</span>
<span class="n">_FIVE</span> <span class="o">=</span> <span class="s1">&#39;__property_cache_uid_&#39;</span>
<span class="n">KEYS</span> <span class="o">=</span> <span class="p">[</span><span class="n">_ONE</span><span class="p">,</span> <span class="n">_TWO</span><span class="p">,</span> <span class="n">_THREE</span><span class="p">,</span> <span class="n">_FOUR</span><span class="p">,</span> <span class="n">_FIVE</span><span class="p">]</span>
<span class="n">VERS</span> <span class="o">=</span> <span class="mf">0.1</span>
<span class="k">def</span> <span class="nf">data_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">VERS</span>
<span class="k">def</span> <span class="nf">one</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ONE</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">three</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_THREE</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">four</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_FOUR</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">five</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_FIVE</span><span class="p">)</span>
<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>
<span class="k">def</span> <span class="nf">print_n_sleep</span><span class="p">(</span><span class="n">k</span><span class="p">):</span>
<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>
<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>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ONE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;one&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;two&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_THREE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;three&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FOUR</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;four&#39;</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_FIVE</span><span class="p">:</span>
<span class="n">print_n_sleep</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="k">return</span> <span class="s1">&#39;five&#39;</span>
<span class="k">return</span> <span class="n">default</span>
<span class="k">def</span> <span class="nf">keys</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">KEYS</span>
<span class="k">def</span> <span class="nf">uid</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">class</span> <span class="nc">tsd_cache_pickle</span><span class="p">(</span><span class="n">test_slow_data</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__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="n">test_slow_data</span><span class="o">.</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="bp">self</span><span class="o">.</span><span class="n">_cached_data</span> <span class="o">=</span> <span class="n">caching</span><span class="o">.</span><span class="n">property_cache_pickle</span><span class="p">(</span><span class="n">test_slow_data</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="s1">&#39;cache.pickle&#39;</span><span class="p">,</span> <span class="n">load_all_on_init</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">two</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">test_slow_data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_TWO</span><span class="p">)</span>
<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>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cached_data</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>
<span class="n">data</span> <span class="o">=</span> <span class="n">tsd_cache_pickle</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Testing property_cache (pickle):</span><span class="se">\\</span><span class="s1">n--------------------------------&#39;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">one</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">two</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">three</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">four</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">five</span><span class="p">())</span>
</pre></div>
</div>
<p>Will result on the first execution to the following output (with a long execution time):</p>
<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>\<span class="n">n</span><span class="o">--------------------------------</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">103</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">103</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">1</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">107</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Loading</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">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;one&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">107</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="n">one</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">2</span>
<span class="n">two</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">_property_cache_data_version_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">36</span><span class="p">,</span><span class="mi">112</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;three&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">36</span><span class="p">,</span><span class="mi">113</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="n">three</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">_property_cache_uid_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">116</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;four&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">117</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="n">four</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="n">__property_cache_uid_</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">120</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Loading</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;__property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">source</span> <span class="n">instance</span> <span class="p">(</span><span class="s1">&#39;five&#39;</span><span class="p">)</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">121</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="n">five</span>
</pre></div>
</div>
<p>With every following execution (slow for getting “two” which is not cached - see implementation):</p>
<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>\<span class="n">n</span><span class="o">--------------------------------</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">200</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">42</span><span class="p">,</span><span class="mi">200</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</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> <span class="p">(</span><span class="s1">&#39;one&#39;</span><span class="p">)</span>
<span class="n">one</span>
<span class="n">slow</span> <span class="n">get</span> <span class="n">executed</span> <span class="k">for</span> <span class="mi">2</span>
<span class="n">two</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">201</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_data_version_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;three&#39;</span><span class="p">)</span>
<span class="n">three</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">201</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;_property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;four&#39;</span><span class="p">)</span>
<span class="n">four</span>
<span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">14</span> <span class="mi">00</span><span class="p">:</span><span class="mi">50</span><span class="p">:</span><span class="mi">45</span><span class="p">,</span><span class="mi">201</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">caching</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">PickCache</span><span class="p">:</span> <span class="n">Providing</span> <span class="nb">property</span> <span class="k">for</span> <span class="s1">&#39;__property_cache_uid_&#39;</span> <span class="kn">from</span> <span class="nn">cache</span> <span class="p">(</span><span class="s1">&#39;five&#39;</span><span class="p">)</span>
<span class="n">five</span>
</pre></div>
</div>
<dl class="method">
<dt id="caching.property_cache_pickle.get">
<code class="descname">get</code><span class="sig-paren">(</span><em>key</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle.get" title="Permalink to this definition"></a></dt>
<dd><p>Method to get the cached property. If key does not exists in cache, the property will be loaded from source_instance and stored in cache (file).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> – key for value to get.</li>
<li><strong>default</strong> – value to be returned, if key does not exists.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">value for a given key or default value.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="caching.property_cache_pickle.keys">
<code class="descname">keys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#caching.property_cache_pickle.keys" title="Permalink to this definition"></a></dt>
<dd><p>Method to get the available keys (from <code class="xref py py-data docutils literal notranslate"><span class="pre">source_instance</span></code>).</p>
</dd></dl>
</dd></dl>
</div>
<div class="toctree-wrapper compound">
</div>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
</ul>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2021, Dirk Alders
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>