<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: XmlSimple::Cache</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">XmlSimple::Cache</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/xml-simple-1_0_12/lib/xmlsimple_rb.html">
                lib/xml-simple-1.0.12/lib/xmlsimple.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
A simple cache for XML documents that were already transformed by xml_in.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000007">new</a>&nbsp;&nbsp;
      <a href="#M000013">restore_mem_copy</a>&nbsp;&nbsp;
      <a href="#M000011">restore_mem_share</a>&nbsp;&nbsp;
      <a href="#M000009">restore_storable</a>&nbsp;&nbsp;
      <a href="#M000012">save_mem_copy</a>&nbsp;&nbsp;
      <a href="#M000010">save_mem_share</a>&nbsp;&nbsp;
      <a href="#M000008">save_storable</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000007" class="method-detail">
        <a name="M000007"></a>

        <div class="method-heading">
          <a href="#M000007" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates and initializes a <a href="Cache.html#M000007">new</a> <a
href="Cache.html">Cache</a> object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000007-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 20</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
      <span class="ruby-ivar">@mem_share_cache</span> = {}
      <span class="ruby-ivar">@mem_copy_cache</span>  = {}
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000013" class="method-detail">
        <a name="M000013"></a>

        <div class="method-heading">
          <a href="#M000013" class="method-signature">
          <span class="method-name">restore_mem_copy</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a memory cache. If restoring the data
structure failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000013-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 87</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_mem_copy</span>(<span class="ruby-identifier">filename</span>)
      <span class="ruby-identifier">data</span> = <span class="ruby-identifier">get_from_memory_cache</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-ivar">@mem_share_cache</span>)
      <span class="ruby-identifier">data</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">data</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">data</span>
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">restore_mem_share</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a shared memory cache. You should consider
these elements as &quot;read only&quot;. If restoring the data structure
failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 67</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_mem_share</span>(<span class="ruby-identifier">filename</span>)
      <span class="ruby-identifier">get_from_memory_cache</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-ivar">@mem_share_cache</span>)
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">restore_storable</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Restores a data structure from a file. If restoring the data structure
failed for any reason, nil will be returned.
</p>
<table>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 41</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restore_storable</span>(<span class="ruby-identifier">filename</span>)
      <span class="ruby-identifier">cache_file</span> = <span class="ruby-identifier">get_cache_filename</span>(<span class="ruby-identifier">filename</span>)
      <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">cache_file</span>)
      <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">cache_file</span>).<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">mtime</span>(<span class="ruby-identifier">filename</span>).<span class="ruby-identifier">to_i</span>
      <span class="ruby-identifier">data</span> = <span class="ruby-keyword kw">nil</span>
      <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cache_file</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">data</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">f</span>) }
      <span class="ruby-identifier">data</span>
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">save_mem_copy</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Copies a data structure to a memory cache.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be copied.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 77</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_mem_copy</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
      <span class="ruby-ivar">@mem_share_cache</span>[<span class="ruby-identifier">filename</span>] = [<span class="ruby-constant">Time</span><span class="ruby-operator">::</span><span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">data</span>)]
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">save_mem_share</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves a data structure in a shared memory cache.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be saved.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 56</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_mem_share</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
      <span class="ruby-ivar">@mem_share_cache</span>[<span class="ruby-identifier">filename</span>] = [<span class="ruby-constant">Time</span><span class="ruby-operator">::</span><span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">data</span>]
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">save_storable</span><span class="method-args">(data, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves a data structure into a file.
</p>
<table>
<tr><td valign="top">data:</td><td>Data structure to be saved.

</td></tr>
<tr><td valign="top">filename:</td><td>Name of the file belonging to the data structure.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
<span class="ruby-comment cmt"># File lib/xml-simple-1.0.12/lib/xmlsimple.rb, line 31</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_storable</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">filename</span>)
      <span class="ruby-identifier">cache_file</span> = <span class="ruby-identifier">get_cache_filename</span>(<span class="ruby-identifier">filename</span>)
      <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">cache_file</span>, <span class="ruby-value str">&quot;w+&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">f</span>) }
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>