613 lines
16 KiB
HTML
613 lines
16 KiB
HTML
<!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>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<title>
|
|
Class: CacheFileStore
|
|
|
|
— Documentation by YARD 0.8.6.1
|
|
|
|
</title>
|
|
|
|
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
|
|
|
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
hasFrames = window.top.frames.main ? true : false;
|
|
relpath = '';
|
|
framesUrl = "frames.html#!" + escape(window.location.href);
|
|
</script>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
|
|
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
|
|
|
|
</head>
|
|
<body>
|
|
<div id="header">
|
|
<div id="menu">
|
|
|
|
<a href="_index.html">Index (C)</a> »
|
|
|
|
|
|
<span class="title">CacheFileStore</span>
|
|
|
|
|
|
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
|
</div>
|
|
|
|
<div id="search">
|
|
|
|
<a class="full_list_link" id="class_list_link"
|
|
href="class_list.html">
|
|
Class List
|
|
</a>
|
|
|
|
<a class="full_list_link" id="method_list_link"
|
|
href="method_list.html">
|
|
Method List
|
|
</a>
|
|
|
|
<a class="full_list_link" id="file_list_link"
|
|
href="file_list.html">
|
|
File List
|
|
</a>
|
|
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>
|
|
|
|
<iframe id="search_frame"></iframe>
|
|
|
|
<div id="content"><h1>Class: CacheFileStore
|
|
|
|
|
|
|
|
</h1>
|
|
|
|
<dl class="box">
|
|
|
|
<dt class="r1">Inherits:</dt>
|
|
<dd class="r1">
|
|
<span class="inheritName">Object</span>
|
|
|
|
<ul class="fullTree">
|
|
<li>Object</li>
|
|
|
|
<li class="next">CacheFileStore</li>
|
|
|
|
</ul>
|
|
<a href="#" class="inheritanceTree">show all</a>
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dt class="r2 last">Defined in:</dt>
|
|
<dd class="r2 last">lib/common/cache_file_store.rb</dd>
|
|
|
|
</dl>
|
|
<div class="clear"></div>
|
|
|
|
<div id="subclasses">
|
|
<h2>Direct Known Subclasses</h2>
|
|
<p class="children"><span class='object_link'><a href="TyphoeusCache.html" title="TyphoeusCache (class)">TyphoeusCache</a></span></p>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
|
<ul class="summary">
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#serializer-instance_method" title="#serializer (instance method)">- (Object) <strong>serializer</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<span class="note title readonly">readonly</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Returns the value of attribute serializer.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#storage_path-instance_method" title="#storage_path (instance method)">- (Object) <strong>storage_path</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<span class="note title readonly">readonly</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>Returns the value of attribute storage_path.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
<h2>
|
|
Instance Method Summary
|
|
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
|
</h2>
|
|
|
|
<ul class="summary">
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#clean-instance_method" title="#clean (instance method)">- (Object) <strong>clean</strong> </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#get_entry_file_path-instance_method" title="#get_entry_file_path (instance method)">- (Object) <strong>get_entry_file_path</strong>(key) </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#initialize-instance_method" title="#initialize (instance method)">- (CacheFileStore) <strong>initialize</strong>(storage_path, serializer = Marshal) </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span class="note title constructor">constructor</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'>
|
|
<p>The serializer must have the 2 methods .load and .dump.</p>
|
|
</div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#read_entry-instance_method" title="#read_entry (instance method)">- (Object) <strong>read_entry</strong>(key) </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
<li class="public ">
|
|
<span class="summary_signature">
|
|
|
|
<a href="#write_entry-instance_method" title="#write_entry (instance method)">- (Object) <strong>write_entry</strong>(key, data_to_store, cache_ttl) </a>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="summary_desc"><div class='inline'></div></span>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<div id="constructor_details" class="method_details_list">
|
|
<h2>Constructor Details</h2>
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="initialize-instance_method">
|
|
|
|
- (<tt><span class='object_link'><a href="" title="CacheFileStore (class)">CacheFileStore</a></span></tt>) <strong>initialize</strong>(storage_path, serializer = Marshal)
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>The serializer must have the 2 methods .load and .dump</p>
|
|
|
|
<pre class="code ruby"><code class="ruby"><span class='lparen'>(</span><span class='const'>Marshal</span> <span class='kw'>and</span> <span class='const'>YAML</span> <span class='id identifier rubyid_have'>have</span> <span class='id identifier rubyid_them'>them</span><span class='rparen'>)</span></code></pre>
|
|
|
|
<p>YAML is Human Readable, contrary to Marshal which store in a binary format
|
|
Marshal does not need any "require"</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
|
26
|
|
27
|
|
28
|
|
29</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 20</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_storage_path'>storage_path</span><span class='comma'>,</span> <span class='id identifier rubyid_serializer'>serializer</span> <span class='op'>=</span> <span class='const'>Marshal</span><span class='rparen'>)</span>
|
|
<span class='ivar'>@storage_path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_expand_path'>expand_path</span><span class='lparen'>(</span><span class='id identifier rubyid_storage_path'>storage_path</span><span class='rparen'>)</span>
|
|
<span class='ivar'>@serializer</span> <span class='op'>=</span> <span class='id identifier rubyid_serializer'>serializer</span>
|
|
|
|
<span class='comment'># File.directory? for ruby <= 1.9 otherwise,
|
|
</span> <span class='comment'># it makes more sense to do Dir.exist? :/
|
|
</span> <span class='kw'>unless</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_directory?'>directory?</span><span class='lparen'>(</span><span class='ivar'>@storage_path</span><span class='rparen'>)</span>
|
|
<span class='const'>Dir</span><span class='period'>.</span><span class='id identifier rubyid_mkdir'>mkdir</span><span class='lparen'>(</span><span class='ivar'>@storage_path</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="instance_attr_details" class="attr_details">
|
|
<h2>Instance Attribute Details</h2>
|
|
|
|
|
|
<span id=""></span>
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="serializer-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>serializer</strong> <span class="extras">(readonly)</span>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Returns the value of attribute serializer</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
14
|
|
15
|
|
16</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 14</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_serializer'>serializer</span>
|
|
<span class='ivar'>@serializer</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
<span id=""></span>
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="storage_path-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>storage_path</strong> <span class="extras">(readonly)</span>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><div class="docstring">
|
|
<div class="discussion">
|
|
|
|
<p>Returns the value of attribute storage_path</p>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div class="tags">
|
|
|
|
|
|
</div><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
14
|
|
15
|
|
16</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 14</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_storage_path'>storage_path</span>
|
|
<span class='ivar'>@storage_path</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<div id="instance_method_details" class="method_details_list">
|
|
<h2>Instance Method Details</h2>
|
|
|
|
|
|
<div class="method_details first">
|
|
<h3 class="signature first" id="clean-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>clean</strong>
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
31
|
|
32
|
|
33
|
|
34
|
|
35</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 31</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_clean'>clean</span>
|
|
<span class='const'>Dir</span><span class='lbracket'>[</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='ivar'>@storage_path</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>*</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span>
|
|
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_symlink?'>symlink?</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="get_entry_file_path-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>get_entry_file_path</strong>(key)
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
53
|
|
54
|
|
55</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 53</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_get_entry_file_path'>get_entry_file_path</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
|
<span class='const'>File</span><span class='op'>::</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='ivar'>@storage_path</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="read_entry-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>read_entry</strong>(key)
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
37
|
|
38
|
|
39
|
|
40
|
|
41
|
|
42
|
|
43</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 37</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_read_entry'>read_entry</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
|
<span class='id identifier rubyid_entry_file_path'>entry_file_path</span> <span class='op'>=</span> <span class='id identifier rubyid_get_entry_file_path'>get_entry_file_path</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
|
|
|
<span class='kw'>if</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_entry_file_path'>entry_file_path</span><span class='rparen'>)</span>
|
|
<span class='kw'>return</span> <span class='ivar'>@serializer</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_entry_file_path'>entry_file_path</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="method_details ">
|
|
<h3 class="signature " id="write_entry-instance_method">
|
|
|
|
- (<tt>Object</tt>) <strong>write_entry</strong>(key, data_to_store, cache_ttl)
|
|
|
|
|
|
|
|
|
|
|
|
</h3><table class="source_code">
|
|
<tr>
|
|
<td>
|
|
<pre class="lines">
|
|
|
|
|
|
45
|
|
46
|
|
47
|
|
48
|
|
49
|
|
50
|
|
51</pre>
|
|
</td>
|
|
<td>
|
|
<pre class="code"><span class="info file"># File 'lib/common/cache_file_store.rb', line 45</span>
|
|
|
|
<span class='kw'>def</span> <span class='id identifier rubyid_write_entry'>write_entry</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_data_to_store'>data_to_store</span><span class='comma'>,</span> <span class='id identifier rubyid_cache_ttl'>cache_ttl</span><span class='rparen'>)</span>
|
|
<span class='kw'>if</span> <span class='id identifier rubyid_cache_ttl'>cache_ttl</span> <span class='op'>></span> <span class='int'>0</span>
|
|
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_get_entry_file_path'>get_entry_file_path</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>w</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span>
|
|
<span class='id identifier rubyid_f'>f</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='ivar'>@serializer</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_data_to_store'>data_to_store</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
|
<span class='kw'>end</span>
|
|
<span class='kw'>end</span>
|
|
<span class='kw'>end</span></pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="footer">
|
|
Generated on Tue Apr 30 23:05:06 2013 by
|
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
0.8.6.1 (ruby-1.9.3).
|
|
</div>
|
|
|
|
</body>
|
|
</html> |