Update version according to OSCI-883
[packages/precise/mcollective.git] / doc / MCollective / Cache.html
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
8         <title>Module: MCollective::Cache</title>
9
10         <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
12         <script src="../js/jquery.js" type="text/javascript"
13                 charset="utf-8"></script>
14         <script src="../js/thickbox-compressed.js" type="text/javascript"
15                 charset="utf-8"></script>
16         <script src="../js/quicksearch.js" type="text/javascript"
17                 charset="utf-8"></script>
18         <script src="../js/darkfish.js" type="text/javascript"
19                 charset="utf-8"></script>
20
21 </head>
22 <body class="module">
23
24         <div id="metadata">
25                 <div id="file-metadata">
26                         <div id="file-list-section" class="section">
27                                 <h3 class="section-header">In Files</h3>
28                                 <div class="section-body">
29                                         <ul>
30                                         
31                                                 <li><a href="../lib/mcollective/cache_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
32                                                         class="thickbox" title="lib/mcollective/cache.rb">lib/mcollective/cache.rb</a></li>
33                                         
34                                         </ul>
35                                 </div>
36                         </div>
37
38                         
39                 </div>
40
41                 <div id="class-metadata">
42
43                         <!-- Parent Class -->
44                         
45
46                         <!-- Namespace Contents -->
47                         
48
49                         <!-- Method Quickref -->
50                         
51                         <div id="method-list-section" class="section">
52                                 <h3 class="section-header">Methods</h3>
53                                 <ul class="link-list">
54                                         
55                                         <li><a href="#M000340">::check_cache!</a></li>
56                                         
57                                         <li><a href="#M000342">::delete!</a></li>
58                                         
59                                         <li><a href="#M000341">::has_cache?</a></li>
60                                         
61                                         <li><a href="#M000349">::invalidate!</a></li>
62                                         
63                                         <li><a href="#M000344">::read</a></li>
64                                         
65                                         <li><a href="#M000339">::setup</a></li>
66                                         
67                                         <li><a href="#M000348">::synchronize</a></li>
68                                         
69                                         <li><a href="#M000345">::ttl</a></li>
70                                         
71                                         <li><a href="#M000343">::write</a></li>
72                                         
73                                 </ul>
74                         </div>
75                         
76
77                         <!-- Included Modules -->
78                         
79                 </div>
80
81                 <div id="project-metadata">
82                         
83                         
84                         <div id="fileindex-section" class="section project-section">
85                                 <h3 class="section-header">Files</h3>
86                                 <ul>
87                                 
88                                         <li class="file"><a href="../COPYING.html">COPYING</a></li>
89                                 
90                                         <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
91                                 
92                                         <li class="file"><a href="../README.html">README</a></li>
93                                 
94                                         <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
95                                 
96                                         <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
97                                 
98                                         <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
99                                 
100                                         <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
101                                 
102                                         <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
103                                 
104                                         <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
105                                 
106                                         <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
107                                 
108                                         <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
109                                 
110                                         <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
111                                 
112                                         <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
113                                 
114                                         <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
115                                 
116                                         <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
117                                 
118                                         <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
119                                 
120                                         <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
121                                 
122                                         <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
123                                 
124                                         <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
125                                 
126                                         <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
127                                 
128                                 </ul>
129                         </div>
130                         
131
132                         <div id="classindex-section" class="section project-section">
133                                 <h3 class="section-header">Class Index
134                                         <span class="search-toggle"><img src="../images/find.png"
135                                                 height="16" width="16" alt="[+]"
136                                                 title="show/hide quicksearch" /></span></h3>
137                                 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
138                                 <fieldset>
139                                         <legend>Quicksearch</legend>
140                                         <input type="text" name="quicksearch" value=""
141                                                 class="quicksearch-field" />
142                                 </fieldset>
143                                 </form>
144
145                                 <ul class="link-list">
146                                 
147                                         <li><a href="../MCollective.html">MCollective</a></li>
148                                 
149                                         <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
150                                 
151                                         <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
152                                 
153                                         <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
154                                 
155                                         <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
156                                 
157                                         <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
158                                 
159                                         <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
160                                 
161                                         <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
162                                 
163                                         <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
164                                 
165                                         <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
166                                 
167                                         <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
168                                 
169                                         <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
170                                 
171                                         <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
172                                 
173                                         <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
174                                 
175                                         <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
176                                 
177                                         <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
178                                 
179                                         <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
180                                 
181                                         <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
182                                 
183                                         <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
184                                 
185                                         <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
186                                 
187                                         <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
188                                 
189                                         <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
190                                 
191                                         <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
192                                 
193                                         <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
194                                 
195                                         <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
196                                 
197                                         <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
198                                 
199                                         <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
200                                 
201                                         <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
202                                 
203                                         <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
204                                 
205                                         <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
206                                 
207                                         <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
208                                 
209                                         <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
210                                 
211                                         <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
212                                 
213                                         <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
214                                 
215                                         <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
216                                 
217                                         <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
218                                 
219                                         <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
220                                 
221                                         <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
222                                 
223                                         <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
224                                 
225                                         <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
226                                 
227                                         <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
228                                 
229                                         <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
230                                 
231                                         <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
232                                 
233                                         <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
234                                 
235                                         <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
236                                 
237                                         <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
238                                 
239                                         <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
240                                 
241                                         <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
242                                 
243                                         <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
244                                 
245                                         <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
246                                 
247                                         <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
248                                 
249                                         <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
250                                 
251                                         <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
252                                 
253                                         <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
254                                 
255                                         <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
256                                 
257                                         <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
258                                 
259                                         <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
260                                 
261                                         <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
262                                 
263                                         <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
264                                 
265                                         <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
266                                 
267                                         <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
268                                 
269                                         <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
270                                 
271                                         <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
272                                 
273                                         <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
274                                 
275                                         <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
276                                 
277                                         <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
278                                 
279                                         <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
280                                 
281                                         <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
282                                 
283                                         <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
284                                 
285                                         <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
286                                 
287                                         <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
288                                 
289                                         <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
290                                 
291                                         <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
292                                 
293                                         <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
294                                 
295                                         <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
296                                 
297                                         <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
298                                 
299                                         <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
300                                 
301                                         <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
302                                 
303                                         <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
304                                 
305                                         <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
306                                 
307                                         <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
308                                 
309                                         <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
310                                 
311                                         <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
312                                 
313                                         <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
314                                 
315                                         <li><a href="../Array.html">Array</a></li>
316                                 
317                                         <li><a href="../Dir.html">Dir</a></li>
318                                 
319                                         <li><a href="../Object.html">Object</a></li>
320                                 
321                                         <li><a href="../String.html">String</a></li>
322                                 
323                                         <li><a href="../Symbol.html">Symbol</a></li>
324                                 
325                                 </ul>
326                                 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
327                         </div>
328
329                         
330                 </div>
331         </div>
332
333         <div id="documentation">
334                 <h1 class="module">MCollective::Cache</h1>
335
336                 <div id="description">
337                         <p>
338 A class to manage a number of named caches. Each cache can have a unique
339 timeout for keys in it and each cache has an independent Mutex protecting
340 access to it.
341 </p>
342 <p>
343 This cache is setup early in the process of loading the mcollective
344 libraries, before any threads are created etc making it suitable as a cross
345 thread cache or just a store for Mutexes you need to use across threads
346 like in an <a href="Agent.html">Agent</a> or something.
347 </p>
348 <pre>
349    # sets up a new cache, noop if it already exist
350    Cache.setup(:ddl, 600)
351    =&gt; true
352
353    # writes an item to the :ddl cache, this item will
354    # be valid on the cache for 600 seconds
355    Cache.write(:ddl, :something, &quot;value&quot;)
356    =&gt; &quot;value&quot;
357
358    # reads from the cache, read failures due to non existing
359    # data or expired data will raise an exception
360    Cache.read(:ddl, :something)
361    =&gt; &quot;value&quot;
362
363    # time left till expiry, raises if nothing is found
364    Cache.ttl(:ddl, :something)
365    =&gt; 500
366
367    # forcibly evict something from the cache
368    Cache.invalidate!(:ddl, :something)
369    =&gt; &quot;value&quot;
370
371    # deletes an entire named cache and its mutexes
372    Cache.delete!(:ddl)
373    =&gt; true
374
375    # you can also just use this cache as a global mutex store
376    Cache.setup(:mylock)
377
378    Cache.synchronize(:mylock) do
379      do_something()
380    end
381 </pre>
382
383                 </div>
384
385                 <!-- Constants -->
386                 
387
388                 <!-- Attributes -->
389                 
390
391                 <!-- Methods -->
392                 
393                 <div id="public-class-method-details" class="method-section section">
394                         <h3 class="section-header">Public Class Methods</h3>
395
396                 
397                         <div id="check-cache--method" class="method-detail ">
398                                 <a name="M000340"></a>
399
400                                 <div class="method-heading">
401                                 
402                                         <span class="method-name">check_cache!</span><span
403                                                 class="method-args">(cache_name)</span>
404                                         <span class="method-click-advice">click to toggle source</span>
405                                 
406                                 </div>
407
408                                 <div class="method-description">
409                                         
410                                         <p class="missing-docs">(Not documented)</p>
411                                         
412
413                                         
414                                         <div class="method-source-code"
415                                                 id="check-cache--source">
416 <pre>
417     <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 70</span>
418 70:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
419 71:       <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC13</span>, <span class="ruby-value str">&quot;Could not find a cache called '%{cache_name}'&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:cache_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cache_name</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">has_cache?</span>(<span class="ruby-identifier">cache_name</span>)
420 72:     <span class="ruby-keyword kw">end</span></pre>
421                                         </div>
422                                         
423                                 </div>
424
425                                 
426                         </div>
427
428                 
429                         <div id="delete--method" class="method-detail ">
430                                 <a name="M000342"></a>
431
432                                 <div class="method-heading">
433                                 
434                                         <span class="method-name">delete!</span><span
435                                                 class="method-args">(cache_name)</span>
436                                         <span class="method-click-advice">click to toggle source</span>
437                                 
438                                 </div>
439
440                                 <div class="method-description">
441                                         
442                                         <p class="missing-docs">(Not documented)</p>
443                                         
444
445                                         
446                                         <div class="method-source-code"
447                                                 id="delete--source">
448 <pre>
449     <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 80</span>
450 80:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">delete!</span>(<span class="ruby-identifier">cache_name</span>)
451 81:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
452 82: 
453 83:       <span class="ruby-ivar">@locks_mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
454 84:         <span class="ruby-ivar">@cache_locks</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">cache_name</span>)
455 85:         <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">cache_name</span>)
456 86:       <span class="ruby-keyword kw">end</span>
457 87: 
458 88:       <span class="ruby-keyword kw">true</span>
459 89:     <span class="ruby-keyword kw">end</span></pre>
460                                         </div>
461                                         
462                                 </div>
463
464                                 
465                         </div>
466
467                 
468                         <div id="has-cache--method" class="method-detail ">
469                                 <a name="M000341"></a>
470
471                                 <div class="method-heading">
472                                 
473                                         <span class="method-name">has_cache?</span><span
474                                                 class="method-args">(cache_name)</span>
475                                         <span class="method-click-advice">click to toggle source</span>
476                                 
477                                 </div>
478
479                                 <div class="method-description">
480                                         
481                                         <p class="missing-docs">(Not documented)</p>
482                                         
483
484                                         
485                                         <div class="method-source-code"
486                                                 id="has-cache--source">
487 <pre>
488     <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 74</span>
489 74:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">has_cache?</span>(<span class="ruby-identifier">cache_name</span>)
490 75:       <span class="ruby-ivar">@locks_mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
491 76:         <span class="ruby-ivar">@cache</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">cache_name</span>)
492 77:       <span class="ruby-keyword kw">end</span>
493 78:     <span class="ruby-keyword kw">end</span></pre>
494                                         </div>
495                                         
496                                 </div>
497
498                                 
499                         </div>
500
501                 
502                         <div id="invalidate--method" class="method-detail ">
503                                 <a name="M000349"></a>
504
505                                 <div class="method-heading">
506                                 
507                                         <span class="method-name">invalidate!</span><span
508                                                 class="method-args">(cache_name, key)</span>
509                                         <span class="method-click-advice">click to toggle source</span>
510                                 
511                                 </div>
512
513                                 <div class="method-description">
514                                         
515                                         <p class="missing-docs">(Not documented)</p>
516                                         
517
518                                         
519                                         <div class="method-source-code"
520                                                 id="invalidate--source">
521 <pre>
522      <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 139</span>
523 139:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">invalidate!</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">key</span>)
524 140:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
525 141: 
526 142:       <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
527 143:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>)
528 144: 
529 145:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
530 146:       <span class="ruby-keyword kw">end</span>
531 147:     <span class="ruby-keyword kw">end</span></pre>
532                                         </div>
533                                         
534                                 </div>
535
536                                 
537                         </div>
538
539                 
540                         <div id="read-method" class="method-detail ">
541                                 <a name="M000344"></a>
542
543                                 <div class="method-heading">
544                                 
545                                         <span class="method-name">read</span><span
546                                                 class="method-args">(cache_name, key)</span>
547                                         <span class="method-click-advice">click to toggle source</span>
548                                 
549                                 </div>
550
551                                 <div class="method-description">
552                                         
553                                         <p class="missing-docs">(Not documented)</p>
554                                         
555
556                                         
557                                         <div class="method-source-code"
558                                                 id="read-source">
559 <pre>
560      <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 103</span>
561 103:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">key</span>)
562 104:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
563 105: 
564 106:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ttl</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">key</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
565 107:         <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC11</span>, <span class="ruby-value str">&quot;Cache expired on '%{cache_name}' key '%{item}'&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:cache_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">:item</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">key</span>)
566 108:       <span class="ruby-keyword kw">end</span>
567 109: 
568 110:       <span class="ruby-identifier">log_code</span>(<span class="ruby-identifier">:PLMC12</span>, <span class="ruby-value str">&quot;Cache hit on '%{cache_name}' key '%{item}'&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:cache_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">:item</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">key</span>)
569 111: 
570 112:       <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
571 113:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">key</span>][<span class="ruby-identifier">:value</span>]
572 114:       <span class="ruby-keyword kw">end</span>
573 115:     <span class="ruby-keyword kw">end</span></pre>
574                                         </div>
575                                         
576                                 </div>
577
578                                 
579                         </div>
580
581                 
582                         <div id="setup-method" class="method-detail ">
583                                 <a name="M000339"></a>
584
585                                 <div class="method-heading">
586                                 
587                                         <span class="method-name">setup</span><span
588                                                 class="method-args">(cache_name, ttl=300)</span>
589                                         <span class="method-click-advice">click to toggle source</span>
590                                 
591                                 </div>
592
593                                 <div class="method-description">
594                                         
595                                         <p class="missing-docs">(Not documented)</p>
596                                         
597
598                                         
599                                         <div class="method-source-code"
600                                                 id="setup-source">
601 <pre>
602     <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 56</span>
603 56:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">setup</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">ttl</span>=<span class="ruby-value">300</span>)
604 57:       <span class="ruby-ivar">@locks_mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
605 58:         <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@cache_locks</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">cache_name</span>)
606 59: 
607 60:         <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>] = <span class="ruby-constant">Mutex</span>.<span class="ruby-identifier">new</span>
608 61: 
609 62:         <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
610 63:           <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>] = {<span class="ruby-identifier">:max_age</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Float</span>(<span class="ruby-identifier">ttl</span>)}
611 64:         <span class="ruby-keyword kw">end</span>
612 65:       <span class="ruby-keyword kw">end</span>
613 66: 
614 67:       <span class="ruby-keyword kw">true</span>
615 68:     <span class="ruby-keyword kw">end</span></pre>
616                                         </div>
617                                         
618                                 </div>
619
620                                 
621                         </div>
622
623                 
624                         <div id="synchronize-method" class="method-detail ">
625                                 <a name="M000348"></a>
626
627                                 <div class="method-heading">
628                                 
629                                         <span class="method-name">synchronize</span><span
630                                                 class="method-args">(cache_name)</span>
631                                         <span class="method-click-advice">click to toggle source</span>
632                                 
633                                 </div>
634
635                                 <div class="method-description">
636                                         
637                                         <p class="missing-docs">(Not documented)</p>
638                                         
639
640                                         
641                                         <div class="method-source-code"
642                                                 id="synchronize-source">
643 <pre>
644      <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 129</span>
645 129:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">synchronize</span>(<span class="ruby-identifier">cache_name</span>)
646 130:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
647 131: 
648 132:       <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC14</span>, <span class="ruby-value str">&quot;No block supplied to synchronize on cache '%{cache_name}'&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:cache_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cache_name</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>
649 133: 
650 134:       <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
651 135:         <span class="ruby-keyword kw">yield</span>
652 136:       <span class="ruby-keyword kw">end</span>
653 137:     <span class="ruby-keyword kw">end</span></pre>
654                                         </div>
655                                         
656                                 </div>
657
658                                 
659                         </div>
660
661                 
662                         <div id="ttl-method" class="method-detail ">
663                                 <a name="M000345"></a>
664
665                                 <div class="method-heading">
666                                 
667                                         <span class="method-name">ttl</span><span
668                                                 class="method-args">(cache_name, key)</span>
669                                         <span class="method-click-advice">click to toggle source</span>
670                                 
671                                 </div>
672
673                                 <div class="method-description">
674                                         
675                                         <p class="missing-docs">(Not documented)</p>
676                                         
677
678                                         
679                                         <div class="method-source-code"
680                                                 id="ttl-source">
681 <pre>
682      <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 117</span>
683 117:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">ttl</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">key</span>)
684 118:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
685 119: 
686 120:       <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
687 121:         <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>)
688 122:           <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC15</span>, <span class="ruby-value str">&quot;No item called '%{item}' for cache '%{cache_name}'&quot;</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:cache_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">:item</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">key</span>)
689 123:         <span class="ruby-keyword kw">end</span>
690 124: 
691 125:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">:max_age</span>] <span class="ruby-operator">-</span> (<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">key</span>][<span class="ruby-identifier">:cache_create_time</span>])
692 126:       <span class="ruby-keyword kw">end</span>
693 127:     <span class="ruby-keyword kw">end</span></pre>
694                                         </div>
695                                         
696                                 </div>
697
698                                 
699                         </div>
700
701                 
702                         <div id="write-method" class="method-detail ">
703                                 <a name="M000343"></a>
704
705                                 <div class="method-heading">
706                                 
707                                         <span class="method-name">write</span><span
708                                                 class="method-args">(cache_name, key, value)</span>
709                                         <span class="method-click-advice">click to toggle source</span>
710                                 
711                                 </div>
712
713                                 <div class="method-description">
714                                         
715                                         <p class="missing-docs">(Not documented)</p>
716                                         
717
718                                         
719                                         <div class="method-source-code"
720                                                 id="write-source">
721 <pre>
722      <span class="ruby-comment cmt"># File lib/mcollective/cache.rb, line 91</span>
723  91:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">cache_name</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
724  92:       <span class="ruby-identifier">check_cache!</span>(<span class="ruby-identifier">cache_name</span>)
725  93: 
726  94:       <span class="ruby-ivar">@cache_locks</span>[<span class="ruby-identifier">cache_name</span>].<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
727  95:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">key</span>] <span class="ruby-operator">||=</span> {}
728  96:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">key</span>][<span class="ruby-identifier">:cache_create_time</span>] = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
729  97:         <span class="ruby-ivar">@cache</span>[<span class="ruby-identifier">cache_name</span>][<span class="ruby-identifier">key</span>][<span class="ruby-identifier">:value</span>] = <span class="ruby-identifier">value</span>
730  98:       <span class="ruby-keyword kw">end</span>
731  99: 
732 100:       <span class="ruby-identifier">value</span>
733 101:     <span class="ruby-keyword kw">end</span></pre>
734                                         </div>
735                                         
736                                 </div>
737
738                                 
739                         </div>
740
741                 
742                 </div>
743         
744
745         </div>
746
747
748         <div id="rdoc-debugging-section-dump" class="debugging-section">
749         
750                 <p>Disabled; run with --debug to generate this.</p>
751         
752         </div>
753
754         <div id="validator-badges">
755                 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
756                 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
757                         Rdoc Generator</a> 1.1.6</small>.</p>
758         </div>
759
760 </body>
761 </html>
762