<!doctype html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>sqlobject.cache module — SQLObject 3.7.0 documentation</title> <link rel="stylesheet" href="../_static/bizstyle.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" 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/bizstyle.js"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!--[if lt IE 9]> <script type="text/javascript" src="_static/css3-mediaqueries.js"></script> <![endif]--> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/api/sqlobject.cache.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-sqlobject.cache"> <span id="sqlobject-cache-module"></span><h1>sqlobject.cache module<a class="headerlink" href="#module-sqlobject.cache" title="Permalink to this headline">¶</a></h1> <p>This implements the instance caching in SQLObject. Caching is relatively aggressive. All objects are retained so long as they are in memory, by keeping weak references to objects. We also keep other objects in a cache that doesn’t allow them to be garbage collected (unless caching is turned off).</p> <dl class="class"> <dt id="sqlobject.cache.CacheFactory"> <em class="property">class </em><code class="descclassname">sqlobject.cache.</code><code class="descname">CacheFactory</code><span class="sig-paren">(</span><em>cullFrequency=100</em>, <em>cullFraction=2</em>, <em>cache=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory" title="Permalink to this definition">¶</a></dt> <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> <p>CacheFactory caches object creation. Each object should be referenced by a single hashable ID (note tuples of hashable values are also hashable).</p> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.allIDs"> <code class="descname">allIDs</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.allIDs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.allIDs" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the IDs of all objects in the cache.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.clear"> <code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.clear"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.clear" title="Permalink to this definition">¶</a></dt> <dd><p>Removes everything from the cache. Warning! This can cause duplicate objects in memory.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.created"> <code class="descname">created</code><span class="sig-paren">(</span><em>id</em>, <em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.created"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.created" title="Permalink to this definition">¶</a></dt> <dd><p>Inserts and object into the cache. Should be used when no one else knows about the object yet, so there cannot be any object already in the cache. After a database INSERT is an example of this situation.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.cull"> <code class="descname">cull</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.cull"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.cull" title="Permalink to this definition">¶</a></dt> <dd><p>Runs through the cache and expires objects</p> <p>E.g., if <code class="docutils literal notranslate"><span class="pre">cullFraction</span></code> is 3, then every third object is moved to the ‘expired’ (aka weakref) cache.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.expire"> <code class="descname">expire</code><span class="sig-paren">(</span><em>id</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.expire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.expire" title="Permalink to this definition">¶</a></dt> <dd><p>Expires a single object. Typically called after a delete. Doesn’t even keep a weakref. (@@: bad name?)</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.expireAll"> <code class="descname">expireAll</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.expireAll"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.expireAll" title="Permalink to this definition">¶</a></dt> <dd><p>Expires all objects, moving them all into the expired/weakref cache.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.finishPut"> <code class="descname">finishPut</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.finishPut"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.finishPut" title="Permalink to this definition">¶</a></dt> <dd><p>Releases the lock that is retained when .get() is called and returns None.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.get"> <code class="descname">get</code><span class="sig-paren">(</span><em>id</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.get" title="Permalink to this definition">¶</a></dt> <dd><p>This method can cause deadlocks! tryGet is safer</p> <p>This returns the object found in cache, or None. If None, then the cache will remain locked! This is so that the calling function can create the object in a threadsafe manner before releasing the lock. You should use this like (note that <code class="docutils literal notranslate"><span class="pre">cache</span></code> is actually a CacheSet object in this example):</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">obj</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">some_id</span><span class="p">,</span> <span class="n">my_class</span><span class="p">)</span> <span class="k">if</span> <span class="n">obj</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">try</span><span class="p">:</span> <span class="n">obj</span> <span class="o">=</span> <span class="n">create_object</span><span class="p">(</span><span class="n">some_id</span><span class="p">)</span> <span class="n">cache</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">some_id</span><span class="p">,</span> <span class="n">my_class</span><span class="p">,</span> <span class="n">obj</span><span class="p">)</span> <span class="k">finally</span><span class="p">:</span> <span class="n">cache</span><span class="o">.</span><span class="n">finishPut</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span> </pre></div> </div> <p>This method checks both the main cache (which retains references) and the ‘expired’ cache, which retains only weak references.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.getAll"> <code class="descname">getAll</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.getAll"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.getAll" title="Permalink to this definition">¶</a></dt> <dd><p>Return all the objects in the cache.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.put"> <code class="descname">put</code><span class="sig-paren">(</span><em>id</em>, <em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.put"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.put" title="Permalink to this definition">¶</a></dt> <dd><p>Puts an object into the cache. Should only be called after .get(), so that duplicate objects don’t end up in the cache.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheFactory.tryGet"> <code class="descname">tryGet</code><span class="sig-paren">(</span><em>id</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheFactory.tryGet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheFactory.tryGet" title="Permalink to this definition">¶</a></dt> <dd><p>This returns None, or the object in cache.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="sqlobject.cache.CacheSet"> <em class="property">class </em><code class="descclassname">sqlobject.cache.</code><code class="descname">CacheSet</code><span class="sig-paren">(</span><em>*args</em>, <em>**kw</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet" title="Permalink to this definition">¶</a></dt> <dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p> <p>A CacheSet is used to collect and maintain a series of caches. In SQLObject, there is one CacheSet per connection, and one Cache in the CacheSet for each class, since IDs are not unique across classes. It contains methods similar to Cache, but that take a <code class="docutils literal notranslate"><span class="pre">cls</span></code> argument.</p> <dl class="method"> <dt id="sqlobject.cache.CacheSet.allIDs"> <code class="descname">allIDs</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.allIDs"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.allIDs" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.allSubCaches"> <code class="descname">allSubCaches</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.allSubCaches"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.allSubCaches" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.allSubCachesByClassNames"> <code class="descname">allSubCachesByClassNames</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.allSubCachesByClassNames"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.allSubCachesByClassNames" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.clear"> <code class="descname">clear</code><span class="sig-paren">(</span><em>cls=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.clear"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.clear" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.created"> <code class="descname">created</code><span class="sig-paren">(</span><em>id</em>, <em>cls</em>, <em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.created"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.created" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.expire"> <code class="descname">expire</code><span class="sig-paren">(</span><em>id</em>, <em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.expire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.expire" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.finishPut"> <code class="descname">finishPut</code><span class="sig-paren">(</span><em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.finishPut"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.finishPut" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.get"> <code class="descname">get</code><span class="sig-paren">(</span><em>id</em>, <em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.get" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.getAll"> <code class="descname">getAll</code><span class="sig-paren">(</span><em>cls=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.getAll"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.getAll" title="Permalink to this definition">¶</a></dt> <dd><p>Returns all instances in the cache for the given class or all classes.</p> </dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.put"> <code class="descname">put</code><span class="sig-paren">(</span><em>id</em>, <em>cls</em>, <em>obj</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.put"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.put" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.tryGet"> <code class="descname">tryGet</code><span class="sig-paren">(</span><em>id</em>, <em>cls</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.tryGet"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.tryGet" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.tryGetByName"> <code class="descname">tryGetByName</code><span class="sig-paren">(</span><em>id</em>, <em>clsname</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.tryGetByName"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.tryGetByName" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="method"> <dt id="sqlobject.cache.CacheSet.weakrefAll"> <code class="descname">weakrefAll</code><span class="sig-paren">(</span><em>cls=None</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/sqlobject/cache.html#CacheSet.weakrefAll"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sqlobject.cache.CacheSet.weakrefAll" title="Permalink to this definition">¶</a></dt> <dd><p>Move all objects in the cls (or if not given, then in all classes) to the weakref dictionary, where they can be collected.</p> </dd></dl> </dd></dl> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">SQLObject 3.7.0 documentation</a> »</li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2004-2018, Ian Bicking and contributors. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.4. </div> </body> </html>