cachetastic 2.1.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/LICENSE +21 -0
  2. data/README +57 -43
  3. data/doc/classes/Cachetastic/Adapters.html +180 -0
  4. data/doc/classes/Cachetastic/Adapters/Base.html +206 -123
  5. data/doc/classes/Cachetastic/Adapters/File.html +17 -130
  6. data/doc/classes/Cachetastic/Adapters/LocalMemory.html +7 -228
  7. data/doc/classes/Cachetastic/Adapters/Memcached.html +193 -0
  8. data/doc/classes/Cachetastic/Cache.html +425 -0
  9. data/doc/classes/Cachetastic/Cacheable.html +26 -30
  10. data/doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html +66 -62
  11. data/doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html +30 -30
  12. data/doc/classes/Cachetastic/Logger.html +31 -33
  13. data/doc/created.rid +1 -1
  14. data/doc/files/{lib/cachetastic/adapters/html_file_rb.html → LICENSE.html} +29 -34
  15. data/doc/files/README.html +91 -57
  16. data/doc/files/lib/cachetastic/adapters/base_rb.html +1 -39
  17. data/doc/files/lib/cachetastic/adapters/file_rb.html +1 -21
  18. data/doc/files/lib/cachetastic/adapters/local_memory_rb.html +1 -9
  19. data/doc/files/lib/cachetastic/{ruby_extensions/kernel_rb.html → adapters/memcached_rb.html} +4 -4
  20. data/doc/files/lib/cachetastic/{ruby_extensions/string_rb.html → cache_rb.html} +5 -5
  21. data/doc/files/lib/cachetastic/cacheable_rb.html +1 -1
  22. data/doc/files/lib/cachetastic/{caches/base_rb.html → extensions/string_rb.html} +5 -5
  23. data/doc/files/lib/cachetastic/logger_rb.html +1 -7
  24. data/doc/files/lib/cachetastic/{adapters/store_object_rb.html → store_object_rb.html} +3 -3
  25. data/doc/files/lib/cachetastic_rb.html +4 -95
  26. data/doc/fr_class_index.html +3 -15
  27. data/doc/fr_file_index.html +5 -16
  28. data/doc/fr_method_index.html +26 -78
  29. data/lib/cachetastic.rb +16 -70
  30. data/lib/cachetastic/adapters/base.rb +178 -76
  31. data/lib/cachetastic/adapters/file.rb +63 -46
  32. data/lib/cachetastic/adapters/local_memory.rb +36 -67
  33. data/lib/cachetastic/adapters/memcached.rb +114 -0
  34. data/lib/cachetastic/cache.rb +165 -0
  35. data/lib/cachetastic/cacheable.rb +19 -15
  36. data/lib/cachetastic/extensions/string.rb +8 -0
  37. data/lib/cachetastic/logger.rb +41 -41
  38. data/lib/cachetastic/store_object.rb +22 -0
  39. metadata +43 -64
  40. data/bin/cachetastic_drb_server +0 -115
  41. data/doc/classes/ActiveRecord/Base.html +0 -194
  42. data/doc/classes/CGI/Session/CachetasticStore.html +0 -124
  43. data/doc/classes/Cachetastic/Adapters/Drb.html +0 -332
  44. data/doc/classes/Cachetastic/Adapters/FileBase.html +0 -309
  45. data/doc/classes/Cachetastic/Adapters/HtmlFile.html +0 -224
  46. data/doc/classes/Cachetastic/Adapters/Memcache.html +0 -498
  47. data/doc/classes/Cachetastic/Caches/Base.html +0 -643
  48. data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html +0 -179
  49. data/doc/classes/Cachetastic/Caches/MackSessionCache.html +0 -119
  50. data/doc/classes/Cachetastic/Caches/PageCache.html +0 -121
  51. data/doc/classes/Cachetastic/Caches/RailsSessionCache.html +0 -154
  52. data/doc/classes/Cachetastic/Connection.html +0 -212
  53. data/doc/classes/Cachetastic/Errors/UnsupportedAdapter.html +0 -146
  54. data/doc/classes/Object.html +0 -222
  55. data/doc/classes/String.html +0 -172
  56. data/doc/files/lib/cachetastic/adapters/drb_rb.html +0 -115
  57. data/doc/files/lib/cachetastic/adapters/file_base_rb.html +0 -109
  58. data/doc/files/lib/cachetastic/adapters/memcache_rb.html +0 -127
  59. data/doc/files/lib/cachetastic/caches/mack_session_cache_rb.html +0 -107
  60. data/doc/files/lib/cachetastic/caches/page_cache_rb.html +0 -109
  61. data/doc/files/lib/cachetastic/caches/rails_session_cache_rb.html +0 -107
  62. data/doc/files/lib/cachetastic/connection_rb.html +0 -107
  63. data/doc/files/lib/cachetastic/errors/unsupported_adapter_rb.html +0 -101
  64. data/doc/files/lib/cachetastic/rails_extensions/active_record_base_rb.html +0 -101
  65. data/doc/files/lib/cachetastic/rails_extensions/cgi_session_store_rb.html +0 -109
  66. data/doc/files/lib/cachetastic/ruby_extensions/object_rb.html +0 -101
  67. data/lib/cachetastic/adapters/drb.rb +0 -51
  68. data/lib/cachetastic/adapters/file_base.rb +0 -86
  69. data/lib/cachetastic/adapters/html_file.rb +0 -68
  70. data/lib/cachetastic/adapters/memcache.rb +0 -114
  71. data/lib/cachetastic/adapters/store_object.rb +0 -28
  72. data/lib/cachetastic/caches/base.rb +0 -238
  73. data/lib/cachetastic/caches/mack_session_cache.rb +0 -3
  74. data/lib/cachetastic/caches/page_cache.rb +0 -6
  75. data/lib/cachetastic/caches/rails_session_cache.rb +0 -12
  76. data/lib/cachetastic/connection.rb +0 -24
  77. data/lib/cachetastic/errors/unsupported_adapter.rb +0 -7
  78. data/lib/cachetastic/rails_extensions/active_record_base.rb +0 -24
  79. data/lib/cachetastic/rails_extensions/cgi_session_store.rb +0 -59
  80. data/lib/cachetastic/ruby_extensions/kernel.rb +0 -25
  81. data/lib/cachetastic/ruby_extensions/object.rb +0 -22
  82. data/lib/cachetastic/ruby_extensions/string.rb +0 -15
  83. data/test/active_record_test.rb +0 -89
  84. data/test/cacheable_test.rb +0 -88
  85. data/test/cachetastic_unit_test.rb +0 -74
  86. data/test/config.rb +0 -30
  87. data/test/drb_adapter_test.rb +0 -14
  88. data/test/file_adapter_test.rb +0 -49
  89. data/test/memcache_adapter_test.rb +0 -18
  90. data/test/test_helper.rb +0 -75
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 Mark Bates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README CHANGED
@@ -1,65 +1,79 @@
1
- =Configuration:
1
+ =What is Cachetastic?
2
+ Cachetastic is an incredibly easy to use and administer caching framework. Just because it is easy to use, does not mean that
3
+ it is light with features. Cachetastic allows you to create classes that extend <tt>Cachetastic::Cache</tt>, configure them
4
+ each individually, and much more.
2
5
 
3
- # this will dump into the log, configuration info for each cache, as well as the .inspect
4
- # for each object returned from the cache
5
- configatron.cachetastic_default_options.debug = false
6
+ Unlike other systems each cache in your system can use different backends via the use of adapters that get assigned to each
7
+ cache, and globally. You can define different expiration times, loggers, marshal methods, and more! And again, you can choose to
8
+ define these settings globally, or for each cache!
6
9
 
7
- # this is the type of file store to be used for this cache.
8
- # more adapters can be developed and plugged in as desired
9
- configatron.cachetastic_default_options.adapter = :local_memory # local_memory | memcache | file | drb | html_file (default: local_memory)
10
+ Adapters are easy to write, so if the built in adapters don't float your boat, you can easily knock one off in short order.
10
11
 
11
- # this will marshall objects into and out of the store.
12
- configatron.cachetastic_default_options.marshall_method = :none # none | yaml | ruby (default: none)
12
+ ==Configuration:
13
+ Configuration of Cachetastic is done using the Configatron gem. I would recommend reading the documentation on it first, http://configatron.mackframework.com, before continuing.
13
14
 
14
- # this sets how long objects will live in the cache before they are auto expired.
15
- configatron.cachetastic_default_options.default_expiry = 86400 # time in seconds (default: 24 hours)
15
+ All configuration settings hang off of the <tt>cachetastic</tt> namespace on <tt>configatron</tt>. The default settings
16
+ all hang off the <tt>defaults</tt> namespace on the <tt>cachetastic</tt> namespace, as shown below:
16
17
 
17
- # when setting objects into the cache the expiry_swing is +/- to the expiry time.
18
- # example: if the expiry time is 1 hour, and the swing is 15 minutes,
19
- # objects will go into the cache with an expiry time sometime between 45 mins and 75 mins.
20
- configatron.cachetastic_default_options.expiry_swing = 60 * 15 # time in seconds (default: 0)
18
+ # This will write detailed information to the logger.
19
+ configatron.cachetastic.defaults.debug = false
21
20
 
22
- # these options get passed on directly to the store.
23
- # listed below are options for memcache:
24
- configatron.cachetastic_default_options.store_options.c_threshold = "10_000"
25
- configatron.cachetastic_default_options.store_options.compression = true
26
- configatron.cachetastic_default_options.store_options.debug = false
27
- configatron.cachetastic_default_options.store_options.readonly = false
28
- configatron.cachetastic_default_options.store_options.urlencode = false
29
-
30
- # set the servers to be used for memcache
31
- configatron.cachetastic_default_options.servers = ["127.0.0.1:11211"] # ip:port used for memcache
21
+ # This is the type of file store to be used for this cache.
22
+ # More adapters can be developed and plugged in as desired.
23
+ # The default is Cachetastic::Adapters::LocalMemory
24
+ configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
25
+ configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::File
26
+ configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::Memcached
27
+
28
+ # This will marshall objects into and out of the store.
29
+ # The default is :none, except for Cachetastic::Adapters::File, which defaults to :yaml
30
+ configatron.cachetastic.defaults.marshall_method = :none
31
+ configatron.cachetastic.defaults.marshall_method = :yaml
32
+ configatron.cachetastic.defaults.marshall_method = :ruby
32
33
 
33
- # listed below are the options for file:
34
- configatron.cachetastic_default_options.store_options.dir = "/cachetastic/caches"
34
+ # This sets how long objects will live in the cache before they are auto expired.
35
+ configatron.cachetastic.defaults.default_expiry = 86400 # time in seconds (default: 24 hours)
35
36
 
36
- # listed below are the options for drb:
37
- configatron.cachetastic_default_options.servers = ["druby://127.0.0.1:61676"]
37
+ # When setting objects into the cache the expiry_swing is +/- to the expiry time.
38
+ # Example: if the expiry time is 1 minute, and the swing is 15 seconds,
39
+ # objects will go into the cache with an expiry time sometime between 45 seconds and 75 seconds.
40
+ # The default is 0 seconds.
41
+ configatron.cachetastic.defaults.expiry_swing = 15
42
+
43
+ # Configure logging for the system.
44
+ # n number of logs can be configured for a cache.
45
+ log_1 = Logger.new(STDOUT)
46
+ log_1.level = Logger::DEBUG
47
+ log_2 = Logger.new("log/cachetastic.log")
48
+ log_2.level = Logger::ERROR
49
+ configatron.cachetastic.defaults.logger = [log_1, log_2]
50
+
51
+ Overriding settings per cache is very simple. Let's take the following two caches:
38
52
 
39
- # configure logging for this cache
40
- # n number of logs can be configured for a cache
41
- log_1 = Logger.new(STDOUT)
42
- log_1.level = Logger::DEBUG
43
- log_2 = Logger.new("log/cachetastic.log")
44
- log_2.level = Logger::ERROR
45
- configatron.cachetastic_default_options.logger = [log_1, log_2]
53
+ class UserCache < Cachetastic::Cache
54
+ end
55
+
56
+ class Admin::UserCache < Cachetastic::Cache
57
+ end
46
58
 
47
- =Cachetastic::Drb::Server
48
- If you want to use Drb and the Cachetastic::Adapters::Drb adapter, you'll have to use the Cachetastic::Drb::Server that comes with Cachetastic. Using this server is simple. It gets installed as a binary when you install the Cachetastic gem.
59
+ If we wanted to set the <tt>UserCache</tt> to use the <tt>Cachetastic::Adapters::File</tt> adapter and we wanted to set the adapter for
60
+ the <tt>Admin::UserCache</tt> to use <tt>Cachetastic::Adapters::Memcached</tt>, we would configure them like such:
49
61
 
50
- $ cachetastic_drb_server # that will start the drb server on the host 127.0.0.1 on the port 61676
62
+ configatron.cachetastic.user_cache.adapter = Cachetastic::Adapters::File
63
+ configatron.cachetastic.admin.user_cache.adapter = Cachetastic::Adapters::Memcached
51
64
 
52
- The server takes to command line parameters: -h <host> -p <port> -v <verbose> -rv <really verbose>
65
+ In this scenario we have changed the adapters for each of the classes. All of the other default settings will remain intact for
66
+ each of those classes. This makes it incredibly easy to just change the one parameter you need, and not have to reset them all.
53
67
 
54
- =Examples:
68
+ ==Examples:
55
69
 
56
- class MyAwesomeCache < Cachetastic::Caches::Base
70
+ class MyAwesomeCache < Cachetastic::Cache
57
71
  end
58
72
 
59
73
  MyAwesomeCache.set(1, [1,2,3])
60
74
  MyAwesomeCache.get(1) # => [1,2,3]
61
75
 
62
- class MyAwesomeCache < Cachetastic::Caches::Base
76
+ class MyAwesomeCache < Cachetastic::Cache
63
77
  class << self
64
78
  def get(key, x, y)
65
79
  super(key) do
@@ -0,0 +1,180 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Cachetastic::Adapters</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Cachetastic::Adapters</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/cachetastic/adapters/base_rb.html">
59
+ lib/cachetastic/adapters/base.rb
60
+ </a>
61
+ <br />
62
+ <a href="../../files/lib/cachetastic/adapters/file_rb.html">
63
+ lib/cachetastic/adapters/file.rb
64
+ </a>
65
+ <br />
66
+ <a href="../../files/lib/cachetastic/adapters/local_memory_rb.html">
67
+ lib/cachetastic/adapters/local_memory.rb
68
+ </a>
69
+ <br />
70
+ <a href="../../files/lib/cachetastic/adapters/memcached_rb.html">
71
+ lib/cachetastic/adapters/memcached.rb
72
+ </a>
73
+ <br />
74
+ </td>
75
+ </tr>
76
+
77
+ </table>
78
+ </div>
79
+ <!-- banner header -->
80
+
81
+ <div id="bodyContent">
82
+
83
+
84
+
85
+ <div id="contextContent">
86
+
87
+
88
+
89
+ </div>
90
+
91
+ <div id="method-list">
92
+ <h3 class="section-bar">Methods</h3>
93
+
94
+ <div class="name-list">
95
+ <a href="#M000001">build</a>&nbsp;&nbsp;
96
+ </div>
97
+ </div>
98
+
99
+ </div>
100
+
101
+
102
+ <!-- if includes -->
103
+
104
+ <div id="section">
105
+
106
+ <div id="class-list">
107
+ <h3 class="section-bar">Classes and Modules</h3>
108
+
109
+ Class <a href="Adapters/Base.html" class="link">Cachetastic::Adapters::Base</a><br />
110
+ Class <a href="Adapters/File.html" class="link">Cachetastic::Adapters::File</a><br />
111
+ Class <a href="Adapters/LocalMemory.html" class="link">Cachetastic::Adapters::LocalMemory</a><br />
112
+ Class <a href="Adapters/Memcached.html" class="link">Cachetastic::Adapters::Memcached</a><br />
113
+
114
+ </div>
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ <!-- if method_list -->
123
+ <div id="methods">
124
+ <h3 class="section-bar">Public Class methods</h3>
125
+
126
+ <div id="method-M000001" class="method-detail">
127
+ <a name="M000001"></a>
128
+
129
+ <div class="method-heading">
130
+ <a href="#M000001" class="method-signature">
131
+ <span class="method-name">build</span><span class="method-args">(klass)</span>
132
+ </a>
133
+ </div>
134
+
135
+ <div class="method-description">
136
+ <p>
137
+ This method will return the appropriate <tt><a
138
+ href="Adapters/Base.html">Cachetastic::Adapters::Base</a></tt> class that
139
+ is defined for the Class passed in. If an adapter has not been defined for
140
+ the Class than the default adapter is returned.
141
+ </p>
142
+ <p>
143
+ Examples:
144
+ </p>
145
+ <pre>
146
+ configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
147
+ configatron.cachetastic.user.adapter = Cachetastic::Adapters::Memcached
148
+ Cachetastic::Adapters.build(User).class # =&gt; Cachetastic::Adapters::Memcached
149
+ Cachetastic::Adapters.build(Comment).class # =&gt; Cachetastic::Adapters::LocalMemory
150
+ </pre>
151
+ <p><a class="source-toggle" href="#"
152
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
153
+ <div class="method-source-code" id="M000001-source">
154
+ <pre>
155
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 16</span>
156
+ 16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build</span>(<span class="ruby-identifier">klass</span>)
157
+ 17: <span class="ruby-identifier">adp</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">to_configatron</span>(<span class="ruby-identifier">:cachetastic</span>).<span class="ruby-identifier">adapter</span>
158
+ 18: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">adp</span>.<span class="ruby-identifier">nil?</span>
159
+ 19: <span class="ruby-identifier">adp</span> = <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">cachetastic</span>.<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">adapter</span>
160
+ 20: <span class="ruby-keyword kw">end</span>
161
+ 21: <span class="ruby-identifier">adp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">klass</span>)
162
+ 22: <span class="ruby-keyword kw">end</span>
163
+ </pre>
164
+ </div>
165
+ </div>
166
+ </div>
167
+
168
+
169
+ </div>
170
+
171
+
172
+ </div>
173
+
174
+
175
+ <div id="validator-badges">
176
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
177
+ </div>
178
+
179
+ </body>
180
+ </html>
@@ -65,9 +65,7 @@
65
65
  <tr class="top-aligned-row">
66
66
  <td><strong>Parent:</strong></td>
67
67
  <td>
68
- <a href="../../Object.html">
69
68
  Object
70
- </a>
71
69
  </td>
72
70
  </tr>
73
71
  </table>
@@ -82,40 +80,32 @@
82
80
 
83
81
  <div id="description">
84
82
  <p>
85
- This class is the interface used to develop adapters for stores. Stores are
86
- where the data is actually held. These could be local memory, memcached, a
87
- database, the file system, etc&#8230; If you implement this API, then you
88
- should be able to plug in different stores for your caches without having
89
- to change any of your code.
83
+ This class should be extended to create <a href="Base.html#M000003">new</a>
84
+ adapters for various backends. It is important that all subclasses call the
85
+ <tt>initialize</tt> method in this base, otherwise things just will not
86
+ work right.
87
+ </p>
88
+ <p>
89
+ This base class provides common functionality and an API for all adapters
90
+ to be used with Cachetastic.
91
+ </p>
92
+ <p>
93
+ The default settings for all adapters are:
94
+ </p>
95
+ <pre>
96
+ configatron.cachetastic.defaults.marshal_method = :none
97
+ configatron.cachetastic.defaults.expiry_swing = 0
98
+ configatron.cachetastic.defaults.default_expiry = 86400
99
+ configatron.cachetastic.defaults.debug = true
100
+ configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
101
+ logger = ::Logger.new(File.join(FileUtils.pwd, 'log', 'cachetastic.log'))
102
+ logger.level = ::Logger::DEBUG
103
+ configatron.cachetastic.defaults.logger = logger
104
+ </pre>
105
+ <p>
106
+ See the README for more information on what each of those settings mean,
107
+ and what are values may be used for each one.
90
108
  </p>
91
- <h3>Methods that need to be implemented:</h3>
92
- <ul>
93
- <li>setup - used to setup the implementation of the adapter.
94
-
95
- </li>
96
- <li>set(key, object, expiry) - sets an object into the store using the given
97
- key and the expiry time.
98
-
99
- </li>
100
- <li>get(key) - returns an object from the store for a given key.
101
-
102
- </li>
103
- <li>delete(key, delay) - deletes an object from the store for a given key. If
104
- the store supports it, a delay can be used.
105
-
106
- </li>
107
- <li>expire_all - expires all objects in the store for a given cache.
108
-
109
- </li>
110
- <li><a href="Base.html#M000037">stats</a> - returns statistics for the store.
111
-
112
- </li>
113
- <li>valid? - used to test whether or not the store is still valid. If this
114
- returns false a <a href="Base.html#M000035">new</a> instance of the adapter
115
- is created by <a href="../Connection.html">Cachetastic::Connection</a>
116
-
117
- </li>
118
- </ul>
119
109
 
120
110
  </div>
121
111
 
@@ -126,11 +116,13 @@ is created by <a href="../Connection.html">Cachetastic::Connection</a>
126
116
  <h3 class="section-bar">Methods</h3>
127
117
 
128
118
  <div class="name-list">
129
- <a href="#M000039">configuration</a>&nbsp;&nbsp;
130
- <a href="#M000038">configuration</a>&nbsp;&nbsp;
131
- <a href="#M000036">debug?</a>&nbsp;&nbsp;
132
- <a href="#M000035">new</a>&nbsp;&nbsp;
133
- <a href="#M000037">stats</a>&nbsp;&nbsp;
119
+ <a href="#M000006">delete</a>&nbsp;&nbsp;
120
+ <a href="#M000007">expire_all</a>&nbsp;&nbsp;
121
+ <a href="#M000004">get</a>&nbsp;&nbsp;
122
+ <a href="#M000003">new</a>&nbsp;&nbsp;
123
+ <a href="#M000005">set</a>&nbsp;&nbsp;
124
+ <a href="#M000008">transform_key</a>&nbsp;&nbsp;
125
+ <a href="#M000009">valid?</a>&nbsp;&nbsp;
134
126
  </div>
135
127
  </div>
136
128
 
@@ -151,18 +143,11 @@ is created by <a href="../Connection.html">Cachetastic::Connection</a>
151
143
  <div class="name-list">
152
144
  <table>
153
145
  <tr class="top-aligned-row context-row">
154
- <td class="context-item-name">logger</td>
155
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
156
- <td class="context-item-desc">
157
- attr_reader :logging
158
-
159
- </td>
160
- </tr>
161
- <tr class="top-aligned-row context-row">
162
- <td class="context-item-name">name</td>
163
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
146
+ <td class="context-item-name">klass</td>
147
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
164
148
  <td class="context-item-desc">
165
- attr_reader :all_options attr_reader :store_options attr_reader :servers
149
+ The Class that this adapter is associated with. Note that it is a
150
+ <em>class</em> reference and not an instance reference.
166
151
 
167
152
  </td>
168
153
  </tr>
@@ -176,146 +161,244 @@ attr_reader :all_options attr_reader :store_options attr_reader :servers
176
161
  <div id="methods">
177
162
  <h3 class="section-bar">Public Class methods</h3>
178
163
 
179
- <div id="method-M000039" class="method-detail">
180
- <a name="M000039"></a>
164
+ <div id="method-M000003" class="method-detail">
165
+ <a name="M000003"></a>
181
166
 
182
167
  <div class="method-heading">
183
- <a href="#M000039" class="method-signature">
184
- <span class="method-name">configuration</span><span class="method-args">(name)</span>
168
+ <a href="#M000003" class="method-signature">
169
+ <span class="method-name">new</span><span class="method-args">(klass)</span>
185
170
  </a>
186
171
  </div>
187
172
 
188
173
  <div class="method-description">
189
174
  <p>
190
- Returns either the options Options need to be specified in configatrion as
191
- the methodized name of the cache with _options attached at the end.
175
+ Creates a <a href="Base.html#M000003">new</a> adapter. It takes a class
176
+ reference to tie the instance of the adapter to a particular class. Note
177
+ that it is a <em>class</em> reference and not an instance reference.
178
+ </p>
179
+ <p>
192
180
  Examples:
193
181
  </p>
194
182
  <pre>
195
- Cachetastic::Caches::PageCache # =&gt; cachetastic_caches_page_cache_options
196
- MyAwesomeCache # =&gt; my_awesome_cache_options
183
+ Cachetastic::Adapters::Base.new(User)
197
184
  </pre>
185
+ <p>
186
+ <a href="../Adapters.html">Adapters</a> are configured using the
187
+ Configatron gem.
188
+ </p>
189
+ <p>
190
+ Examples:
191
+ </p>
192
+ <pre>
193
+ configatron.cachetastic.user.adapter = Cachetastic::Adapters::File
194
+ configatron.cachetastic.user.expiry_time = 5.hours
195
+ configatron.cachetastic.defaults.expiry_time = 24.hours
196
+ </pre>
197
+ <p>
198
+ Refered to each adapter for its specific configuration settings.
199
+ </p>
198
200
  <p><a class="source-toggle" href="#"
199
- onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
200
- <div class="method-source-code" id="M000039-source">
201
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
202
+ <div class="method-source-code" id="M000003-source">
201
203
  <pre>
202
- <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 69</span>
203
- 69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configuration</span>(<span class="ruby-identifier">name</span>)
204
- 70: <span class="ruby-identifier">name</span> = <span class="ruby-node">&quot;#{name}_options&quot;</span>
205
- 71: <span class="ruby-identifier">conf</span> = <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">cachetastic_default_options</span>)
206
- 72: <span class="ruby-identifier">conf</span>
207
- 73: <span class="ruby-keyword kw">end</span>
204
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 67</span>
205
+ 67: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">klass</span>)
206
+ 68: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">klass</span> = <span class="ruby-identifier">klass</span>
207
+ 69: <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">cachetastic</span>.<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">configatron_keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
208
+ 70: <span class="ruby-identifier">define_accessor</span>(<span class="ruby-identifier">key</span>)
209
+ 71: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{key}=&quot;</span>, <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">cachetastic</span>.<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">key</span>))
210
+ 72: <span class="ruby-keyword kw">end</span>
211
+ 73: <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">to_configatron</span>(<span class="ruby-identifier">:cachetastic</span>).<span class="ruby-identifier">configatron_keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
212
+ 74: <span class="ruby-identifier">define_accessor</span>(<span class="ruby-identifier">key</span>)
213
+ 75: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{key}=&quot;</span>, <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">to_configatron</span>(<span class="ruby-identifier">:cachetastic</span>).<span class="ruby-identifier">send</span>(<span class="ruby-identifier">key</span>))
214
+ 76: <span class="ruby-keyword kw">end</span>
215
+ 77: <span class="ruby-keyword kw">end</span>
208
216
  </pre>
209
217
  </div>
210
218
  </div>
211
219
  </div>
212
220
 
213
- <div id="method-M000035" class="method-detail">
214
- <a name="M000035"></a>
221
+ <h3 class="section-bar">Public Instance methods</h3>
222
+
223
+ <div id="method-M000006" class="method-detail">
224
+ <a name="M000006"></a>
215
225
 
216
226
  <div class="method-heading">
217
- <a href="#M000035" class="method-signature">
218
- <span class="method-name">new</span><span class="method-args">(name)</span>
227
+ <a href="#M000006" class="method-signature">
228
+ <span class="method-name">delete</span><span class="method-args">(key)</span>
219
229
  </a>
220
230
  </div>
221
231
 
222
232
  <div class="method-description">
233
+ <p>
234
+ <b>This method MUST be implemented by a subclass!</b>
235
+ </p>
236
+ <p>
237
+ The implementation of this method should take a key and remove an object,
238
+ if it exists, from an underlying persistence store.
239
+ </p>
223
240
  <p><a class="source-toggle" href="#"
224
- onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
225
- <div class="method-source-code" id="M000035-source">
241
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
242
+ <div class="method-source-code" id="M000006-source">
226
243
  <pre>
227
- <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 24</span>
228
- 24: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">name</span>)
229
- 25: <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">name</span>
230
- 26: <span class="ruby-ivar">@logger</span> = <span class="ruby-constant">Cachetastic</span><span class="ruby-operator">::</span><span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">configuration</span>.<span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">:logger</span>, <span class="ruby-operator">::</span><span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">STDOUT</span>)))
231
- 27: <span class="ruby-identifier">setup</span>
232
- 28: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">debug?</span>
233
- 29: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">:self</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">inspect</span>)
234
- 30: <span class="ruby-keyword kw">end</span>
235
- 31: <span class="ruby-keyword kw">end</span>
244
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 101</span>
245
+ 101: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
246
+ 102: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'delete'</span>)
247
+ 103: <span class="ruby-keyword kw">end</span>
236
248
  </pre>
237
249
  </div>
238
250
  </div>
239
251
  </div>
240
252
 
241
- <h3 class="section-bar">Public Instance methods</h3>
253
+ <div id="method-M000007" class="method-detail">
254
+ <a name="M000007"></a>
242
255
 
243
- <div id="method-M000038" class="method-detail">
244
- <a name="M000038"></a>
256
+ <div class="method-heading">
257
+ <a href="#M000007" class="method-signature">
258
+ <span class="method-name">expire_all</span><span class="method-args">()</span>
259
+ </a>
260
+ </div>
261
+
262
+ <div class="method-description">
263
+ <p>
264
+ <b>This method MUST be implemented by a subclass!</b>
265
+ </p>
266
+ <p>
267
+ The implementation of this method is expected to <a
268
+ href="Base.html#M000006">delete</a> all objects belonging to the associated
269
+ cache from the underlying persistence store. It is <b>NOT</b> meant to <a
270
+ href="Base.html#M000006">delete</a> <b>ALL</b> objects across <b>ALL</b>
271
+ caches for the underlying persistence store. That would be very very bad!!
272
+ </p>
273
+ <p><a class="source-toggle" href="#"
274
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
275
+ <div class="method-source-code" id="M000007-source">
276
+ <pre>
277
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 112</span>
278
+ 112: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_all</span>
279
+ 113: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'expire_all'</span>)
280
+ 114: <span class="ruby-keyword kw">end</span>
281
+ </pre>
282
+ </div>
283
+ </div>
284
+ </div>
285
+
286
+ <div id="method-M000004" class="method-detail">
287
+ <a name="M000004"></a>
245
288
 
246
289
  <div class="method-heading">
247
- <a href="#M000038" class="method-signature">
248
- <span class="method-name">configuration</span><span class="method-args">()</span>
290
+ <a href="#M000004" class="method-signature">
291
+ <span class="method-name">get</span><span class="method-args">(key)</span>
249
292
  </a>
250
293
  </div>
251
294
 
252
295
  <div class="method-description">
296
+ <p>
297
+ <b>This method MUST be implemented by a subclass!</b>
298
+ </p>
299
+ <p>
300
+ The implementation of this method should take a key and return an
301
+ associated object, if available, from the underlying persistence layer.
302
+ </p>
253
303
  <p><a class="source-toggle" href="#"
254
- onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
255
- <div class="method-source-code" id="M000038-source">
304
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
305
+ <div class="method-source-code" id="M000004-source">
256
306
  <pre>
257
- <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 58</span>
258
- 58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configuration</span>
259
- 59: <span class="ruby-constant">Cachetastic</span><span class="ruby-operator">::</span><span class="ruby-constant">Adapters</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">configuration</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>)
260
- 60: <span class="ruby-keyword kw">end</span>
307
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 84</span>
308
+ 84: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>)
309
+ 85: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'get'</span>)
310
+ 86: <span class="ruby-keyword kw">end</span>
261
311
  </pre>
262
312
  </div>
263
313
  </div>
264
314
  </div>
265
315
 
266
- <div id="method-M000036" class="method-detail">
267
- <a name="M000036"></a>
316
+ <div id="method-M000005" class="method-detail">
317
+ <a name="M000005"></a>
268
318
 
269
319
  <div class="method-heading">
270
- <a href="#M000036" class="method-signature">
271
- <span class="method-name">debug?</span><span class="method-args">()</span>
320
+ <a href="#M000005" class="method-signature">
321
+ <span class="method-name">set</span><span class="method-args">(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)</span>
272
322
  </a>
273
323
  </div>
274
324
 
275
325
  <div class="method-description">
276
326
  <p>
277
- Returns true/or falsed based on whether or not the debug setting is set to
278
- true in the <a href="Base.html#M000038">configuration</a> file. If the
279
- config setting is set, then false is returned.
327
+ <b>This method MUST be implemented by a subclass!</b>
328
+ </p>
329
+ <p>
330
+ The implementation of this method should take a key, a value, and an expiry
331
+ time and save it to the persistence store, where it should live until it is
332
+ either deleted by the user of the expiry time has passed.
280
333
  </p>
281
334
  <p><a class="source-toggle" href="#"
282
- onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
283
- <div class="method-source-code" id="M000036-source">
335
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
336
+ <div class="method-source-code" id="M000005-source">
284
337
  <pre>
285
- <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 43</span>
286
- 43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug?</span>
287
- 44: <span class="ruby-identifier">configuration</span>.<span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">:debug</span>, <span class="ruby-keyword kw">false</span>)
288
- 45: <span class="ruby-keyword kw">end</span>
338
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 93</span>
339
+ 93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expiry_time</span> = <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">cachetastic</span>.<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">default_expiry</span>)
340
+ 94: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'set'</span>)
341
+ 95: <span class="ruby-keyword kw">end</span>
289
342
  </pre>
290
343
  </div>
291
344
  </div>
292
345
  </div>
293
346
 
294
- <div id="method-M000037" class="method-detail">
295
- <a name="M000037"></a>
347
+ <div id="method-M000008" class="method-detail">
348
+ <a name="M000008"></a>
296
349
 
297
350
  <div class="method-heading">
298
- <a href="#M000037" class="method-signature">
299
- <span class="method-name">stats</span><span class="method-args">()</span>
351
+ <a href="#M000008" class="method-signature">
352
+ <span class="method-name">transform_key</span><span class="method-args">(key)</span>
300
353
  </a>
301
354
  </div>
302
355
 
303
356
  <div class="method-description">
357
+ <p>
358
+ Allows an adapter to transform the key to a safe representation for
359
+ it&#8216;s backend. For example, the key: &#8217;$*&#8230;123()%~q&#8217;
360
+ is not a key for the file system, so the <a
361
+ href="File.html">Cachetastic::Adapters::File</a> class should override this
362
+ to make it safe for the file system.
363
+ </p>
364
+ <p><a class="source-toggle" href="#"
365
+ onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
366
+ <div class="method-source-code" id="M000008-source">
367
+ <pre>
368
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 122</span>
369
+ 122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">transform_key</span>(<span class="ruby-identifier">key</span>)
370
+ 123: <span class="ruby-identifier">key</span>
371
+ 124: <span class="ruby-keyword kw">end</span>
372
+ </pre>
373
+ </div>
374
+ </div>
375
+ </div>
376
+
377
+ <div id="method-M000009" class="method-detail">
378
+ <a name="M000009"></a>
379
+
380
+ <div class="method-heading">
381
+ <a href="#M000009" class="method-signature">
382
+ <span class="method-name">valid?</span><span class="method-args">()</span>
383
+ </a>
384
+ </div>
385
+
386
+ <div class="method-description">
387
+ <p>
388
+ <b>This method MUST be implemented by a subclass!</b>
389
+ </p>
390
+ <p>
391
+ The implementation of this method should return <tt>true</tt> if the
392
+ adapter is in a valid state, and <tt>false</tt> if it is not.
393
+ </p>
304
394
  <p><a class="source-toggle" href="#"
305
- onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
306
- <div class="method-source-code" id="M000037-source">
395
+ onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
396
+ <div class="method-source-code" id="M000009-source">
307
397
  <pre>
308
- <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 47</span>
309
- 47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stats</span>
310
- 48: <span class="ruby-identifier">cache_name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">camelize</span>
311
- 49: <span class="ruby-identifier">adapter_type</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'Cachetastic::Adapters::'</span>, <span class="ruby-value str">''</span>)
312
- 50: <span class="ruby-identifier">s</span> = <span class="ruby-node">&quot;Cache: #{cache_name}\nStore Type: #{adapter_type}\n&quot;</span>
313
- 51: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">servers</span>
314
- 52: <span class="ruby-identifier">servers</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">servers</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">','</span>)
315
- 53: <span class="ruby-identifier">s</span> <span class="ruby-operator">+=</span> <span class="ruby-node">&quot;Servers: #{servers}&quot;</span>
316
- 54: <span class="ruby-keyword kw">end</span>
317
- 55: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>
318
- 56: <span class="ruby-keyword kw">end</span>
398
+ <span class="ruby-comment cmt"># File lib/cachetastic/adapters/base.rb, line 131</span>
399
+ 131: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid?</span>
400
+ 132: <span class="ruby-keyword kw">true</span>
401
+ 133: <span class="ruby-keyword kw">end</span>
319
402
  </pre>
320
403
  </div>
321
404
  </div>