cachetastic-three 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.
- data/LICENSE +21 -0
- data/README +89 -0
- data/doc/classes/Cachetastic/Adapters.html +180 -0
- data/doc/classes/Cachetastic/Adapters/Base.html +419 -0
- data/doc/classes/Cachetastic/Adapters/File.html +135 -0
- data/doc/classes/Cachetastic/Adapters/LocalMemory.html +125 -0
- data/doc/classes/Cachetastic/Adapters/Memcached.html +193 -0
- data/doc/classes/Cachetastic/Cache.html +425 -0
- data/doc/classes/Cachetastic/Cacheable.html +255 -0
- data/doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html +290 -0
- data/doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html +197 -0
- data/doc/classes/Cachetastic/Logger.html +186 -0
- data/doc/created.rid +1 -0
- data/doc/files/LICENSE.html +132 -0
- data/doc/files/README.html +222 -0
- data/doc/files/lib/cachetastic/adapters/base_rb.html +101 -0
- data/doc/files/lib/cachetastic/adapters/file_rb.html +101 -0
- data/doc/files/lib/cachetastic/adapters/local_memory_rb.html +101 -0
- data/doc/files/lib/cachetastic/adapters/memcached_rb.html +101 -0
- data/doc/files/lib/cachetastic/cache_rb.html +101 -0
- data/doc/files/lib/cachetastic/cacheable_rb.html +101 -0
- data/doc/files/lib/cachetastic/extensions/string_rb.html +108 -0
- data/doc/files/lib/cachetastic/logger_rb.html +101 -0
- data/doc/files/lib/cachetastic/store_object_rb.html +101 -0
- data/doc/files/lib/cachetastic_rb.html +112 -0
- data/doc/fr_class_index.html +36 -0
- data/doc/fr_file_index.html +38 -0
- data/doc/fr_method_index.html +52 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/cachetastic.rb +20 -0
- data/lib/cachetastic/adapters/base.rb +178 -0
- data/lib/cachetastic/adapters/file.rb +66 -0
- data/lib/cachetastic/adapters/local_memory.rb +37 -0
- data/lib/cachetastic/adapters/memcached.rb +114 -0
- data/lib/cachetastic/cache.rb +165 -0
- data/lib/cachetastic/cacheable.rb +202 -0
- data/lib/cachetastic/extensions/string.rb +8 -0
- data/lib/cachetastic/logger.rb +49 -0
- data/lib/cachetastic/store_object.rb +22 -0
- metadata +122 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Classes
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Classes</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Classes</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="classes/Cachetastic/Adapters.html">Cachetastic::Adapters</a><br />
|
24
|
+
<a href="classes/Cachetastic/Adapters/Base.html">Cachetastic::Adapters::Base</a><br />
|
25
|
+
<a href="classes/Cachetastic/Adapters/File.html">Cachetastic::Adapters::File</a><br />
|
26
|
+
<a href="classes/Cachetastic/Adapters/LocalMemory.html">Cachetastic::Adapters::LocalMemory</a><br />
|
27
|
+
<a href="classes/Cachetastic/Adapters/Memcached.html">Cachetastic::Adapters::Memcached</a><br />
|
28
|
+
<a href="classes/Cachetastic/Cache.html">Cachetastic::Cache</a><br />
|
29
|
+
<a href="classes/Cachetastic/Cacheable.html">Cachetastic::Cacheable</a><br />
|
30
|
+
<a href="classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html">Cachetastic::Cacheable::ClassAndInstanceMethods</a><br />
|
31
|
+
<a href="classes/Cachetastic/Cacheable/ClassOnlyMethods.html">Cachetastic::Cacheable::ClassOnlyMethods</a><br />
|
32
|
+
<a href="classes/Cachetastic/Logger.html">Cachetastic::Logger</a><br />
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</body>
|
36
|
+
</html>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Files
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Files</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Files</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="files/LICENSE.html">LICENSE</a><br />
|
24
|
+
<a href="files/README.html">README</a><br />
|
25
|
+
<a href="files/lib/cachetastic_rb.html">lib/cachetastic.rb</a><br />
|
26
|
+
<a href="files/lib/cachetastic/adapters/base_rb.html">lib/cachetastic/adapters/base.rb</a><br />
|
27
|
+
<a href="files/lib/cachetastic/adapters/file_rb.html">lib/cachetastic/adapters/file.rb</a><br />
|
28
|
+
<a href="files/lib/cachetastic/adapters/local_memory_rb.html">lib/cachetastic/adapters/local_memory.rb</a><br />
|
29
|
+
<a href="files/lib/cachetastic/adapters/memcached_rb.html">lib/cachetastic/adapters/memcached.rb</a><br />
|
30
|
+
<a href="files/lib/cachetastic/cache_rb.html">lib/cachetastic/cache.rb</a><br />
|
31
|
+
<a href="files/lib/cachetastic/cacheable_rb.html">lib/cachetastic/cacheable.rb</a><br />
|
32
|
+
<a href="files/lib/cachetastic/extensions/string_rb.html">lib/cachetastic/extensions/string.rb</a><br />
|
33
|
+
<a href="files/lib/cachetastic/logger_rb.html">lib/cachetastic/logger.rb</a><br />
|
34
|
+
<a href="files/lib/cachetastic/store_object_rb.html">lib/cachetastic/store_object.rb</a><br />
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
</body>
|
38
|
+
</html>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
3
|
+
<!DOCTYPE html
|
4
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
5
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
6
|
+
|
7
|
+
<!--
|
8
|
+
|
9
|
+
Methods
|
10
|
+
|
11
|
+
-->
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
|
+
<head>
|
14
|
+
<title>Methods</title>
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
16
|
+
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
|
17
|
+
<base target="docwin" />
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
<div id="index">
|
21
|
+
<h1 class="section-bar">Methods</h1>
|
22
|
+
<div id="index-entries">
|
23
|
+
<a href="classes/Cachetastic/Cache.html#M000022">adapter (Cachetastic::Cache)</a><br />
|
24
|
+
<a href="classes/Cachetastic/Adapters.html#M000001">build (Cachetastic::Adapters)</a><br />
|
25
|
+
<a href="classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html#M000015">cache_class (Cachetastic::Cacheable::ClassAndInstanceMethods)</a><br />
|
26
|
+
<a href="classes/Cachetastic/Cacheable.html#M000010">cache_self (Cachetastic::Cacheable)</a><br />
|
27
|
+
<a href="classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html#M000016">cacher (Cachetastic::Cacheable::ClassAndInstanceMethods)</a><br />
|
28
|
+
<a href="classes/Cachetastic/Cache.html#M000025">calculate_expiry_time (Cachetastic::Cache)</a><br />
|
29
|
+
<a href="classes/Cachetastic/Cache.html#M000023">clear_adapter! (Cachetastic::Cache)</a><br />
|
30
|
+
<a href="classes/Cachetastic/Cache.html#M000020">delete (Cachetastic::Cache)</a><br />
|
31
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000006">delete (Cachetastic::Adapters::Base)</a><br />
|
32
|
+
<a href="classes/Cachetastic/Cacheable/ClassOnlyMethods.html#M000013">delete_from_cache (Cachetastic::Cacheable::ClassOnlyMethods)</a><br />
|
33
|
+
<a href="classes/Cachetastic/Cache.html#M000021">expire_all (Cachetastic::Cache)</a><br />
|
34
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000007">expire_all (Cachetastic::Adapters::Base)</a><br />
|
35
|
+
<a href="classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html#M000017">expire_all (Cachetastic::Cacheable::ClassAndInstanceMethods)</a><br />
|
36
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000004">get (Cachetastic::Adapters::Base)</a><br />
|
37
|
+
<a href="classes/Cachetastic/Cache.html#M000018">get (Cachetastic::Cache)</a><br />
|
38
|
+
<a href="classes/Cachetastic/Cacheable/ClassOnlyMethods.html#M000012">get_from_cache (Cachetastic::Cacheable::ClassOnlyMethods)</a><br />
|
39
|
+
<a href="classes/Cachetastic/Cache.html#M000024">logger (Cachetastic::Cache)</a><br />
|
40
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000003">new (Cachetastic::Adapters::Base)</a><br />
|
41
|
+
<a href="classes/Cachetastic/Logger.html#M000026">new (Cachetastic::Logger)</a><br />
|
42
|
+
<a href="classes/Cachetastic/Cache.html#M000019">set (Cachetastic::Cache)</a><br />
|
43
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000005">set (Cachetastic::Adapters::Base)</a><br />
|
44
|
+
<a href="classes/Cachetastic/Cacheable/ClassOnlyMethods.html#M000014">set_into_cache (Cachetastic::Cacheable::ClassOnlyMethods)</a><br />
|
45
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000008">transform_key (Cachetastic::Adapters::Base)</a><br />
|
46
|
+
<a href="classes/Cachetastic/Cacheable.html#M000011">uncache_self (Cachetastic::Cacheable)</a><br />
|
47
|
+
<a href="classes/Cachetastic/Adapters/Memcached.html#M000002">valid? (Cachetastic::Adapters::Memcached)</a><br />
|
48
|
+
<a href="classes/Cachetastic/Adapters/Base.html#M000009">valid? (Cachetastic::Adapters::Base)</a><br />
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
</body>
|
52
|
+
</html>
|
data/doc/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
5
|
+
|
6
|
+
<!--
|
7
|
+
|
8
|
+
cachetastic
|
9
|
+
|
10
|
+
-->
|
11
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
12
|
+
<head>
|
13
|
+
<title>cachetastic</title>
|
14
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
15
|
+
</head>
|
16
|
+
<frameset rows="20%, 80%">
|
17
|
+
<frameset cols="25%,35%,45%">
|
18
|
+
<frame src="fr_file_index.html" title="Files" name="Files" />
|
19
|
+
<frame src="fr_class_index.html" name="Classes" />
|
20
|
+
<frame src="fr_method_index.html" name="Methods" />
|
21
|
+
</frameset>
|
22
|
+
<frame src="files/README.html" name="docwin" />
|
23
|
+
</frameset>
|
24
|
+
</html>
|
data/doc/rdoc-style.css
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
|
2
|
+
body {
|
3
|
+
font-family: Verdana,Arial,Helvetica,sans-serif;
|
4
|
+
font-size: 90%;
|
5
|
+
margin: 0;
|
6
|
+
margin-left: 40px;
|
7
|
+
padding: 0;
|
8
|
+
background: white;
|
9
|
+
}
|
10
|
+
|
11
|
+
h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
|
12
|
+
h1 { font-size: 150%; }
|
13
|
+
h2,h3,h4 { margin-top: 1em; }
|
14
|
+
|
15
|
+
a { background: #eef; color: #039; text-decoration: none; }
|
16
|
+
a:hover { background: #039; color: #eef; }
|
17
|
+
|
18
|
+
/* Override the base stylesheet's Anchor inside a table cell */
|
19
|
+
td > a {
|
20
|
+
background: transparent;
|
21
|
+
color: #039;
|
22
|
+
text-decoration: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
/* and inside a section title */
|
26
|
+
.section-title > a {
|
27
|
+
background: transparent;
|
28
|
+
color: #eee;
|
29
|
+
text-decoration: none;
|
30
|
+
}
|
31
|
+
|
32
|
+
/* === Structural elements =================================== */
|
33
|
+
|
34
|
+
div#index {
|
35
|
+
margin: 0;
|
36
|
+
margin-left: -40px;
|
37
|
+
padding: 0;
|
38
|
+
font-size: 90%;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
div#index a {
|
43
|
+
margin-left: 0.7em;
|
44
|
+
}
|
45
|
+
|
46
|
+
div#index .section-bar {
|
47
|
+
margin-left: 0px;
|
48
|
+
padding-left: 0.7em;
|
49
|
+
background: #ccc;
|
50
|
+
font-size: small;
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
div#classHeader, div#fileHeader {
|
55
|
+
width: auto;
|
56
|
+
color: white;
|
57
|
+
padding: 0.5em 1.5em 0.5em 1.5em;
|
58
|
+
margin: 0;
|
59
|
+
margin-left: -40px;
|
60
|
+
border-bottom: 3px solid #006;
|
61
|
+
}
|
62
|
+
|
63
|
+
div#classHeader a, div#fileHeader a {
|
64
|
+
background: inherit;
|
65
|
+
color: white;
|
66
|
+
}
|
67
|
+
|
68
|
+
div#classHeader td, div#fileHeader td {
|
69
|
+
background: inherit;
|
70
|
+
color: white;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
div#fileHeader {
|
75
|
+
background: #057;
|
76
|
+
}
|
77
|
+
|
78
|
+
div#classHeader {
|
79
|
+
background: #048;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
.class-name-in-header {
|
84
|
+
font-size: 180%;
|
85
|
+
font-weight: bold;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
div#bodyContent {
|
90
|
+
padding: 0 1.5em 0 1.5em;
|
91
|
+
}
|
92
|
+
|
93
|
+
div#description {
|
94
|
+
padding: 0.5em 1.5em;
|
95
|
+
background: #efefef;
|
96
|
+
border: 1px dotted #999;
|
97
|
+
}
|
98
|
+
|
99
|
+
div#description h1,h2,h3,h4,h5,h6 {
|
100
|
+
color: #125;;
|
101
|
+
background: transparent;
|
102
|
+
}
|
103
|
+
|
104
|
+
div#validator-badges {
|
105
|
+
text-align: center;
|
106
|
+
}
|
107
|
+
div#validator-badges img { border: 0; }
|
108
|
+
|
109
|
+
div#copyright {
|
110
|
+
color: #333;
|
111
|
+
background: #efefef;
|
112
|
+
font: 0.75em sans-serif;
|
113
|
+
margin-top: 5em;
|
114
|
+
margin-bottom: 0;
|
115
|
+
padding: 0.5em 2em;
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
/* === Classes =================================== */
|
120
|
+
|
121
|
+
table.header-table {
|
122
|
+
color: white;
|
123
|
+
font-size: small;
|
124
|
+
}
|
125
|
+
|
126
|
+
.type-note {
|
127
|
+
font-size: small;
|
128
|
+
color: #DEDEDE;
|
129
|
+
}
|
130
|
+
|
131
|
+
.xxsection-bar {
|
132
|
+
background: #eee;
|
133
|
+
color: #333;
|
134
|
+
padding: 3px;
|
135
|
+
}
|
136
|
+
|
137
|
+
.section-bar {
|
138
|
+
color: #333;
|
139
|
+
border-bottom: 1px solid #999;
|
140
|
+
margin-left: -20px;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
.section-title {
|
145
|
+
background: #79a;
|
146
|
+
color: #eee;
|
147
|
+
padding: 3px;
|
148
|
+
margin-top: 2em;
|
149
|
+
margin-left: -30px;
|
150
|
+
border: 1px solid #999;
|
151
|
+
}
|
152
|
+
|
153
|
+
.top-aligned-row { vertical-align: top }
|
154
|
+
.bottom-aligned-row { vertical-align: bottom }
|
155
|
+
|
156
|
+
/* --- Context section classes ----------------------- */
|
157
|
+
|
158
|
+
.context-row { }
|
159
|
+
.context-item-name { font-family: monospace; font-weight: bold; color: black; }
|
160
|
+
.context-item-value { font-size: small; color: #448; }
|
161
|
+
.context-item-desc { color: #333; padding-left: 2em; }
|
162
|
+
|
163
|
+
/* --- Method classes -------------------------- */
|
164
|
+
.method-detail {
|
165
|
+
background: #efefef;
|
166
|
+
padding: 0;
|
167
|
+
margin-top: 0.5em;
|
168
|
+
margin-bottom: 1em;
|
169
|
+
border: 1px dotted #ccc;
|
170
|
+
}
|
171
|
+
.method-heading {
|
172
|
+
color: black;
|
173
|
+
background: #ccc;
|
174
|
+
border-bottom: 1px solid #666;
|
175
|
+
padding: 0.2em 0.5em 0 0.5em;
|
176
|
+
}
|
177
|
+
.method-signature { color: black; background: inherit; }
|
178
|
+
.method-name { font-weight: bold; }
|
179
|
+
.method-args { font-style: italic; }
|
180
|
+
.method-description { padding: 0 0.5em 0 0.5em; }
|
181
|
+
|
182
|
+
/* --- Source code sections -------------------- */
|
183
|
+
|
184
|
+
a.source-toggle { font-size: 90%; }
|
185
|
+
div.method-source-code {
|
186
|
+
background: #262626;
|
187
|
+
color: #ffdead;
|
188
|
+
margin: 1em;
|
189
|
+
padding: 0.5em;
|
190
|
+
border: 1px dashed #999;
|
191
|
+
overflow: hidden;
|
192
|
+
}
|
193
|
+
|
194
|
+
div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
195
|
+
|
196
|
+
/* --- Ruby keyword styles --------------------- */
|
197
|
+
|
198
|
+
.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
|
199
|
+
|
200
|
+
.ruby-constant { color: #7fffd4; background: transparent; }
|
201
|
+
.ruby-keyword { color: #00ffff; background: transparent; }
|
202
|
+
.ruby-ivar { color: #eedd82; background: transparent; }
|
203
|
+
.ruby-operator { color: #00ffee; background: transparent; }
|
204
|
+
.ruby-identifier { color: #ffdead; background: transparent; }
|
205
|
+
.ruby-node { color: #ffa07a; background: transparent; }
|
206
|
+
.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
|
207
|
+
.ruby-regexp { color: #ffa07a; background: transparent; }
|
208
|
+
.ruby-value { color: #7fffd4; background: transparent; }
|
data/lib/cachetastic.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
require 'logger'
|
3
|
+
require 'activesupport'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'memcache'
|
6
|
+
|
7
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'cachetastic', '**/*.rb')).each do |f|
|
8
|
+
require File.expand_path(f)
|
9
|
+
end
|
10
|
+
|
11
|
+
configatron.cachetastic.defaults.set_default(:marshal_method, :none)
|
12
|
+
configatron.cachetastic.defaults.set_default(:expiry_swing, 0)
|
13
|
+
configatron.cachetastic.defaults.set_default(:default_expiry, 86400)
|
14
|
+
configatron.cachetastic.defaults.set_default(:debug, true)
|
15
|
+
configatron.cachetastic.defaults.set_default(:adapter, Cachetastic::Adapters::LocalMemory)
|
16
|
+
log_path = File.join(FileUtils.pwd, 'log', 'cachetastic.log')
|
17
|
+
FileUtils.mkdir_p(File.dirname(log_path))
|
18
|
+
logger = ::Logger.new(log_path)
|
19
|
+
logger.level = ::Logger::DEBUG
|
20
|
+
configatron.cachetastic.defaults.set_default(:logger, logger)
|
@@ -0,0 +1,178 @@
|
|
1
|
+
module Cachetastic # :nodoc:
|
2
|
+
module Adapters
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# This method will return the appropriate
|
7
|
+
# <tt>Cachetastic::Adapters::Base</tt> class that is defined
|
8
|
+
# for the Class passed in. If an adapter has not been
|
9
|
+
# defined for the Class than the default adapter is returned.
|
10
|
+
#
|
11
|
+
# Examples:
|
12
|
+
# configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
|
13
|
+
# configatron.cachetastic.user.adapter = Cachetastic::Adapters::Memcached
|
14
|
+
# Cachetastic::Adapters.build(User).class # => Cachetastic::Adapters::Memcached
|
15
|
+
# Cachetastic::Adapters.build(Comment).class # => Cachetastic::Adapters::LocalMemory
|
16
|
+
def build(klass)
|
17
|
+
adp = klass.to_configatron(:cachetastic).adapter
|
18
|
+
if adp.nil?
|
19
|
+
adp = configatron.cachetastic.defaults.adapter
|
20
|
+
end
|
21
|
+
adp.new(klass)
|
22
|
+
end
|
23
|
+
|
24
|
+
end # class << self
|
25
|
+
|
26
|
+
# This class should be extended to create new adapters for various
|
27
|
+
# backends. It is important that all subclasses call the <tt>initialize</tt>
|
28
|
+
# method in this base, otherwise things just will not work right.
|
29
|
+
#
|
30
|
+
# This base class provides common functionality and an API for all
|
31
|
+
# adapters to be used with Cachetastic.
|
32
|
+
#
|
33
|
+
# The default settings for all adapters are:
|
34
|
+
#
|
35
|
+
# configatron.cachetastic.defaults.marshal_method = :none
|
36
|
+
# configatron.cachetastic.defaults.expiry_swing = 0
|
37
|
+
# configatron.cachetastic.defaults.default_expiry = 86400
|
38
|
+
# configatron.cachetastic.defaults.debug = true
|
39
|
+
# configatron.cachetastic.defaults.adapter = Cachetastic::Adapters::LocalMemory
|
40
|
+
# logger = ::Logger.new(File.join(FileUtils.pwd, 'log', 'cachetastic.log'))
|
41
|
+
# logger.level = ::Logger::DEBUG
|
42
|
+
# configatron.cachetastic.defaults.logger = logger
|
43
|
+
#
|
44
|
+
# See the README for more information on what each of those settings mean,
|
45
|
+
# and what are values may be used for each one.
|
46
|
+
class Base
|
47
|
+
|
48
|
+
# The Class that this adapter is associated with. Note that it is a
|
49
|
+
# <i>class</i> reference and not an instance reference.
|
50
|
+
attr_accessor :klass
|
51
|
+
|
52
|
+
# Creates a new adapter. It takes a class reference to tie the
|
53
|
+
# instance of the adapter to a particular class. Note that it is a
|
54
|
+
# <i>class</i> reference and not an instance reference.
|
55
|
+
#
|
56
|
+
# Examples:
|
57
|
+
# Cachetastic::Adapters::Base.new(User)
|
58
|
+
#
|
59
|
+
# Adapters are configured using the Configatron gem.
|
60
|
+
#
|
61
|
+
# Examples:
|
62
|
+
# configatron.cachetastic.user.adapter = Cachetastic::Adapters::File
|
63
|
+
# configatron.cachetastic.user.expiry_time = 5.hours
|
64
|
+
# configatron.cachetastic.defaults.expiry_time = 24.hours
|
65
|
+
#
|
66
|
+
# Refered to each adapter for its specific configuration settings.
|
67
|
+
def initialize(klass)
|
68
|
+
self.klass = klass
|
69
|
+
configatron.cachetastic.defaults.configatron_keys.each do |key|
|
70
|
+
define_accessor(key)
|
71
|
+
self.send("#{key}=", configatron.cachetastic.defaults.send(key))
|
72
|
+
end
|
73
|
+
klass.to_configatron(:cachetastic).configatron_keys.each do |key|
|
74
|
+
define_accessor(key)
|
75
|
+
self.send("#{key}=", klass.to_configatron(:cachetastic).send(key))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# <b>This method MUST be implemented by a subclass!</b>
|
80
|
+
#
|
81
|
+
# The implementation of this method should take a key and return
|
82
|
+
# an associated object, if available, from the underlying persistence
|
83
|
+
# layer.
|
84
|
+
def get(key)
|
85
|
+
raise NoMethodError.new('get')
|
86
|
+
end # get
|
87
|
+
|
88
|
+
# <b>This method MUST be implemented by a subclass!</b>
|
89
|
+
#
|
90
|
+
# The implementation of this method should take a key, a value, and
|
91
|
+
# an expiry time and save it to the persistence store, where it should
|
92
|
+
# live until it is either deleted by the user of the expiry time has passed.
|
93
|
+
def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry)
|
94
|
+
raise NoMethodError.new('set')
|
95
|
+
end # set
|
96
|
+
|
97
|
+
# <b>This method MUST be implemented by a subclass!</b>
|
98
|
+
#
|
99
|
+
# The implementation of this method should take a key and remove
|
100
|
+
# an object, if it exists, from an underlying persistence store.
|
101
|
+
def delete(key)
|
102
|
+
raise NoMethodError.new('delete')
|
103
|
+
end # delete
|
104
|
+
|
105
|
+
# <b>This method MUST be implemented by a subclass!</b>
|
106
|
+
#
|
107
|
+
# The implementation of this method is expected to delete all
|
108
|
+
# objects belonging to the associated cache from the underlying
|
109
|
+
# persistence store. It is <b>NOT</b> meant to delete <b>ALL</b>
|
110
|
+
# objects across <b>ALL</b> caches for the underlying persistence
|
111
|
+
# store. That would be very very bad!!
|
112
|
+
def expire_all
|
113
|
+
raise NoMethodError.new('expire_all')
|
114
|
+
end # expire_all
|
115
|
+
|
116
|
+
# Allows an adapter to transform the key
|
117
|
+
# to a safe representation for it's backend.
|
118
|
+
# For example, the key: '$*...123()%~q' is not a
|
119
|
+
# key for the file system, so the
|
120
|
+
# Cachetastic::Adapters::File class should override
|
121
|
+
# this to make it safe for the file system.
|
122
|
+
def transform_key(key)
|
123
|
+
key
|
124
|
+
end
|
125
|
+
|
126
|
+
# <b>This method MUST be implemented by a subclass!</b>
|
127
|
+
#
|
128
|
+
# The implementation of this method should return <tt>true</tt>
|
129
|
+
# if the adapter is in a valid state, and <tt>false</tt> if it is
|
130
|
+
# not.
|
131
|
+
def valid?
|
132
|
+
true
|
133
|
+
end
|
134
|
+
|
135
|
+
def debug? # :nodoc:
|
136
|
+
return self.debug if self.respond_to?(:debug)
|
137
|
+
return false
|
138
|
+
end
|
139
|
+
|
140
|
+
def marshal(value) # :nodoc:
|
141
|
+
return nil if value.nil?
|
142
|
+
case self.marshal_method.to_sym
|
143
|
+
when :yaml
|
144
|
+
return YAML.dump(value)
|
145
|
+
when :ruby
|
146
|
+
return Marshal.dump(value)
|
147
|
+
else
|
148
|
+
return value
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def unmarshal(value) # :nodoc:
|
153
|
+
return nil if value.nil?
|
154
|
+
case self.marshal_method.to_sym
|
155
|
+
when :yaml
|
156
|
+
return YAML.load(value)
|
157
|
+
when :ruby
|
158
|
+
return Marshal.load(value)
|
159
|
+
else
|
160
|
+
return value
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def define_accessor(key)
|
166
|
+
instance_eval(%{
|
167
|
+
def #{key}
|
168
|
+
@#{key}
|
169
|
+
end
|
170
|
+
def #{key}=(x)
|
171
|
+
@#{key} = x
|
172
|
+
end
|
173
|
+
})
|
174
|
+
end
|
175
|
+
|
176
|
+
end # Base
|
177
|
+
end # Adapters
|
178
|
+
end # Cachetastic
|