doc/classes/Cachetastic/Caches/Base.html in cachetastic-1.1.3 vs doc/classes/Cachetastic/Caches/Base.html in cachetastic-1.1.8
- old
+ new
@@ -76,29 +76,61 @@
<div id="contextContent">
+ <div id="description">
+ <p>
+When creating a new ‘Cache’ this class should be extended. Once
+extended you‘ll only need to override just the methods that are
+different for your cache.
+</p>
+<pre>
+ class MyAwesomeCache < Cachetastic::Caches::Base
+ end
+ MyAwesomeCache.set(1, "One")
+ MyAwesomeCache.get(1) # => "One"
+ MyAwesomeCache.update(1, "One!!")
+ MyAwesomeCache.get(1) # => "One!!"
+ MyAwesomeCache.delete(1)
+ MyAwesomeCache.get(1) # => nil
+ class MyAwesomeCache < Cachetastic::Caches::Base
+ class << self
+ def get(key)
+ super(key) do
+ set(key, key * 10)
+ end
+ end
+ end
+ end
+ MyAwesomeCache.set(1, "One")
+ MyAwesomeCache.get(1) # => "One"
+ MyAwesomeCache.delete(1)
+ MyAwesomeCache.get(1) # => 10
+</pre>
+ </div>
+
+
</div>
<div id="method-list">
<h3 class="section-bar">Methods</h3>
<div class="name-list">
- <a href="#M000033">all_registered_caches</a>
- <a href="#M000041">cache_name</a>
- <a href="#M000037">delete</a>
- <a href="#M000038">expire_all</a>
- <a href="#M000035">get</a>
- <a href="#M000034">inherited</a>
- <a href="#M000043">logger</a>
- <a href="#M000039">populate_all</a>
- <a href="#M000036">set</a>
- <a href="#M000040">stats</a>
- <a href="#M000042">store</a>
+ <a href="#M000032">all_registered_caches</a>
+ <a href="#M000039">cache_name</a>
+ <a href="#M000042">calculate_expiry_time</a>
+ <a href="#M000035">delete</a>
+ <a href="#M000036">expire_all</a>
+ <a href="#M000033">get</a>
+ <a href="#M000041">logger</a>
+ <a href="#M000037">populate_all</a>
+ <a href="#M000034">set</a>
+ <a href="#M000038">stats</a>
+ <a href="#M000040">store</a>
</div>
</div>
</div>
@@ -135,160 +167,222 @@
<!-- if method_list -->
<div id="methods">
<h3 class="section-bar">Public Class methods</h3>
- <div id="method-M000033" class="method-detail">
- <a name="M000033"></a>
+ <div id="method-M000032" class="method-detail">
+ <a name="M000032"></a>
<div class="method-heading">
- <a href="Base.src/M000033.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000033.html');return false;">
+ <a href="Base.src/M000032.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000032.html');return false;">
<span class="method-name">all_registered_caches</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Returns a list of all registered caches in the system.
+</p>
</div>
</div>
- <div id="method-M000041" class="method-detail">
- <a name="M000041"></a>
+ <div id="method-M000039" class="method-detail">
+ <a name="M000039"></a>
<div class="method-heading">
- <a href="Base.src/M000041.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000041.html');return false;">
+ <a href="Base.src/M000039.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000039.html');return false;">
<span class="method-name">cache_name</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Returns a ‘methodize’ version of the cache‘s class name.
+This gets used in logging, namespacing, and as the key in the <a
+href="../Connection.html">Cachetastic::Connection</a> class.
+</p>
+<pre>
+ MyAwesomeCache.cache # => "my_awesome_cache"
+ Cachetastic::Caches::Base # => "cachetastic_caches_base"
+</pre>
</div>
</div>
- <div id="method-M000037" class="method-detail">
- <a name="M000037"></a>
+ <div id="method-M000035" class="method-detail">
+ <a name="M000035"></a>
<div class="method-heading">
- <a href="Base.src/M000037.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000037.html');return false;">
+ <a href="Base.src/M000035.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000035.html');return false;">
<span class="method-name">delete</span><span class="method-args">(key, delay = 0)</span>
</a>
</div>
<div class="method-description">
+ <p>
+Deletes an object from the cache. The optional delay parameter sets an
+offset, in seconds, for when the object should <a
+href="Base.html#M000033">get</a> deleted. The default of 0 means the object
+gets deleted right away.
+</p>
</div>
</div>
- <div id="method-M000038" class="method-detail">
- <a name="M000038"></a>
+ <div id="method-M000036" class="method-detail">
+ <a name="M000036"></a>
<div class="method-heading">
- <a href="Base.src/M000038.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000038.html');return false;">
+ <a href="Base.src/M000036.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000036.html');return false;">
<span class="method-name">expire_all</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Expires all objects for this cache.
+</p>
</div>
</div>
- <div id="method-M000035" class="method-detail">
- <a name="M000035"></a>
+ <div id="method-M000033" class="method-detail">
+ <a name="M000033"></a>
<div class="method-heading">
- <a href="Base.src/M000035.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000035.html');return false;">
- <span class="method-name">get</span><span class="method-args">(key) {|if block_given?| ...}</span>
+ <a href="Base.src/M000033.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000033.html');return false;">
+ <span class="method-name">get</span><span class="method-args">(key) {|key if block_given?| ...}</span>
</a>
</div>
<div class="method-description">
+ <p>
+Returns an object from the cache for a given key. If the object comes back
+as nil and a block is given that block will be run and the results of the
+block will be run. This can be used to JIT caches, just make sure in the
+block to call the <a href="Base.html#M000034">set</a> method because the
+results of the block are not automatically cached.
+</p>
</div>
</div>
- <div id="method-M000034" class="method-detail">
- <a name="M000034"></a>
+ <div id="method-M000041" class="method-detail">
+ <a name="M000041"></a>
<div class="method-heading">
- <a href="Base.src/M000034.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000034.html');return false;">
- <span class="method-name">inherited</span><span class="method-args">(child)</span>
+ <a href="Base.src/M000041.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000041.html');return false;">
+ <span class="method-name">logger</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Returns the <a href="../Logger.html">Cachetastic::Logger</a> for the
+underlying <a href="../Stores/Base.html">Cachetastic::Stores::Base</a>.
+</p>
</div>
</div>
- <div id="method-M000043" class="method-detail">
- <a name="M000043"></a>
+ <div id="method-M000037" class="method-detail">
+ <a name="M000037"></a>
<div class="method-heading">
- <a href="Base.src/M000043.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000043.html');return false;">
- <span class="method-name">logger</span><span class="method-args">()</span>
+ <a href="Base.src/M000037.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000037.html');return false;">
+ <span class="method-name">populate_all</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Raises a MethodNotImplemented exception. This method should be overridden
+in the child class to enable a populating the cache with all things that
+should be in there.
+</p>
</div>
</div>
- <div id="method-M000039" class="method-detail">
- <a name="M000039"></a>
+ <div id="method-M000034" class="method-detail">
+ <a name="M000034"></a>
<div class="method-heading">
- <a href="Base.src/M000039.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000039.html');return false;">
- <span class="method-name">populate_all</span><span class="method-args">()</span>
+ <a href="Base.src/M000034.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000034.html');return false;">
+ <span class="method-name">set</span><span class="method-args">(key, value, expiry = (store.all_options["default_expiry"] || 0))</span>
</a>
</div>
<div class="method-description">
+ <p>
+Set a particular object info the cache for the given key. An optional third
+parameter sets the expiry time for the object in the cache. The default for
+this expiry is <a href="Base.html#M000034">set</a> as either 0, meaning it
+never expires, or if there‘s a default_expiry time <a
+href="Base.html#M000034">set</a> in the config file, that file will be
+used. If there is an expiry_swing <a href="Base.html#M000034">set</a> in
+the config file it will be +/- to the expiry time. See also: <a
+href="Base.html#M000042">calculate_expiry_time</a>
+</p>
</div>
</div>
- <div id="method-M000036" class="method-detail">
- <a name="M000036"></a>
+ <div id="method-M000038" class="method-detail">
+ <a name="M000038"></a>
<div class="method-heading">
- <a href="Base.src/M000036.html" target="Code" class="method-signature"
- onclick="popupCode('Base.src/M000036.html');return false;">
- <span class="method-name">set</span><span class="method-args">(key, value, expiry = (store.all_options["default_expiry"] || 0))</span>
+ <a href="Base.src/M000038.html" target="Code" class="method-signature"
+ onclick="popupCode('Base.src/M000038.html');return false;">
+ <span class="method-name">stats</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+A convenience method that returns statistics for the underlying <a
+href="../Stores/Base.html">Cachetastic::Stores::Base</a> for the cache.
+</p>
</div>
</div>
<div id="method-M000040" class="method-detail">
<a name="M000040"></a>
<div class="method-heading">
<a href="Base.src/M000040.html" target="Code" class="method-signature"
onclick="popupCode('Base.src/M000040.html');return false;">
- <span class="method-name">stats</span><span class="method-args">()</span>
+ <span class="method-name">store</span><span class="method-args">()</span>
</a>
</div>
<div class="method-description">
+ <p>
+Returns the underlying <a
+href="../Stores/Base.html">Cachetastic::Stores::Base</a> for this cache.
+</p>
</div>
</div>
+ <h3 class="section-bar">Private Class methods</h3>
+
<div id="method-M000042" class="method-detail">
<a name="M000042"></a>
<div class="method-heading">
<a href="Base.src/M000042.html" target="Code" class="method-signature"
onclick="popupCode('Base.src/M000042.html');return false;">
- <span class="method-name">store</span><span class="method-args">()</span>
+ <span class="method-name">calculate_expiry_time</span><span class="method-args">(expiry)</span>
</a>
</div>
<div class="method-description">
+ <p>
+If the expiry time is <a href="Base.html#M000034">set</a> to 60 minutes and
+the expiry_swing time is <a href="Base.html#M000034">set</a> to 15 minutes,
+this method will return a number between 45 minutes and 75 minutes.
+</p>
</div>
</div>
</div>
\ No newline at end of file