erector_cache 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +48 -0
- data/README.rdoc +161 -13
- data/VERSION +1 -1
- data/lib/erector_cache/widget.rb +1 -1
- metadata +4 -4
data/README
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
erector_cache
|
2
|
+
|
3
|
+
....:~~~~~~~~~~~~~:~~::::::,..
|
4
|
+
......,~===~=====~~~~~::::::::::::::,..... ..
|
5
|
+
....,~+++=++++++==~~~~:::::::::::::::,... ..
|
6
|
+
..~I?+?????+?+++===~~~~::::::::::::::~:,... .
|
7
|
+
.=I7?I?????+?+++===~~~~~:::::::::::::~~:.... ..
|
8
|
+
.....~$$77II7III?+?++++===~~~~::::::::::::::~~=:......
|
9
|
+
....:ZZ$$7IIIIII???++++++==~~~:::::::::~~~:~~~==,.....
|
10
|
+
....7OZZ$77I777I????+++++==~~::::::::::~~::~~~===, ..
|
11
|
+
...?OOOZ$$$7777II?????+++===~~:::::::::::::~~~~==~....
|
12
|
+
..,7OOO$$$$$7777II??+++==~~~~~::::::::::::~::::~~=,...
|
13
|
+
. ?OOOOZZ$$$77777I??++=++=~~~~:::::::::::::::~~===:...
|
14
|
+
..I8OOO$Z$ZZ77777I???+=+==~~::::::::::,:::::~=+++++...
|
15
|
+
,78OOO$ZZZ$$7777II7ZOOOOZ$7?+~~::::,,,::~~~?I7ZOOZ?..... ..
|
16
|
+
,7O8OO$$ZZZ$77$77ZOO8OOZ$II?+++=::,,,:::~===~+++I$Z:.... ..
|
17
|
+
:7O88O8Z$$$$$$$OOZ???+III777$?+=~~::::::~:=I7+=::~+:~~, ..
|
18
|
+
,7OOO8OOZ77$I$OZIII~~~~=+???++I7I=:~=~=+I$=~I~=~:~+...=,:,
|
19
|
+
..IOOO8OOZ777IZZ+=I++++?+=??I7II7$Z$??I$$$+?+=::~~=:.. ,=?:
|
20
|
+
..?O88O88OZ$$$$7$Z+?+?77ZOO7III$7$ZI=:::Z7+78ZO8$I~=~++,~=..
|
21
|
+
..+O88O8OOZ$777=$7=??$ODN$8?+$I?7787=~~:O$?ZN88$Z8?=~...+:..
|
22
|
+
,:+7ZDDD8OZZ$$7?$Z?IZOII$7?++++?77$??+~:IZ=?+~~=+II=,...+,.
|
23
|
+
.....:II++7O8DOZ$$7$7IIZ??7Z7?~~=+++=+7O7+I?=:+$~=?7I??I?+:..:+..
|
24
|
+
... .?ZOZ?++$8O$$7777??7$=???I?+===~:~77+I?==~:~=~~~~~~~~==.,:..
|
25
|
+
... ,+77?7OI78O777777II+?$=~~~~~~~:::II+$7?+~:~:~~~:,:::::~=:.....
|
26
|
+
....,+77==Z$$8O$7777IIII??I=:::::,,+?II?77I+~,,::=I7~,,.:=++:....
|
27
|
+
.....=7?=?O8$88Z$$$777II?+=+7$IIII=:+$7III77?==~~=+=+?+=~~~~:.....
|
28
|
+
.....~7++7877O8O$$$$77I?+===:~~:::~+IZ$I?+7O$+=~~?++==~::::~:....
|
29
|
+
.....,I+?==?788OZZ$$77II?+==~~~~~===+7ODD8OZ8OZZ8D7+~~++~~~=: ...
|
30
|
+
......I=+=+I7O8OOZZ$777I??+===~~====+?IOO$7$O88Z$$7+=~=+=~==:.....
|
31
|
+
,$++7ZIOD8OZ$$$7777I?++=====?I$ZZZ$Z77ZZOOZ$ZZ$I+~+++=.....
|
32
|
+
~I++?7OO$$$$$$777$77?++=?IZOZOOOOZZOOOOOOZ$ZOZ$Z$+=+~......
|
33
|
+
.,?++?IZO$$Z$$$777777I??I$ZOOOOOOOZZOZZ7II$7IZOOOZI=+~......
|
34
|
+
..,II=:?Z$$$$$$77I77I?78888888OZZZ$77$III7?+?$O8OO$++,.. .
|
35
|
+
...,,..,7$$$$$$77I7777O8O8D888OZ?II:===?=,:.?NNOZO7++,..
|
36
|
+
........?7$$$$$77II77II=+77Z8NNNNDNNN8DNDNMNO7+?7I++~. .
|
37
|
+
........?$$$$$$$7I777I?==+++?IO8OZI==,::,?$7I?==?+==:
|
38
|
+
.....?7$$$$Z$77I7$$7?=++++I??7I+===+?+=?I?===~=+=..
|
39
|
+
..?$$ZZZZ$$$77777I?+=+++II++++=====++===~~==+...
|
40
|
+
. ?$$$ZZZZ$$777777I+=+++?II?+????++?+++=~~==~...
|
41
|
+
. . ..I$$ZZOOOZZ$$777777+=+?+=+?++++==+=~~~~~~~~...
|
42
|
+
.......:$$ZZZOOOOOZZ$777$$?+=+++===~~=~~~~~~~~~~=, ..
|
43
|
+
.....,I$7$$$$$ZOOOOZ$$7$Z7I+=====~~:::~:~~~~~=~.....
|
44
|
+
. ....+77777$$$ZOO88OZZ$$Z$I?+=====~~::~~~~~=~=,.. ..
|
45
|
+
. .,, ......,I77$$7I7777$$ZO888OOZOO$I?+++==~::~~:~=~+~ . . ..
|
46
|
+
. :D88DDDZ7+:.,?7I7$$$7IIIII777$ZOOO888OOZ$II??+====+==++,.
|
47
|
+
..?8Z8O88DDDDO7I??777IIIII?77I7$$ZOOOOOOOOZ$$7I?+===+???,..
|
48
|
+
,Z8OOOOOO888888DD8DDD88DDD$?IIII7$ZOZOOOOOOOOZZZZZ$Z$I=.....
|
data/README.rdoc
CHANGED
@@ -1,16 +1,164 @@
|
|
1
|
-
=
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
= Erector Cache
|
2
|
+
|
3
|
+
Widget caching for Erector.
|
4
|
+
|
5
|
+
<em>Note:
|
6
|
+
This only works at the widget level as this is essentially a fragment caching utility, and will not work for widgets rendered directly from a controller. (widget vs render_widget)</em>
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
sudo gem install erector_cache
|
10
|
+
|
11
|
+
Checkout redis http://github.com/antirez/redis and install
|
12
|
+
|
13
|
+
MAKE SURE REDIS SERVER IS RUNNING
|
14
|
+
|
15
|
+
First, connect to the Redis database. This would most likely go into an environment.rb.
|
16
|
+
|
17
|
+
Lawnchair.connectdb
|
18
|
+
|
19
|
+
This will connect to a default database on localhost, if you want to connect to a particular database you can do:
|
20
|
+
|
21
|
+
Lawnchair.connectdb(Redis.new(:database => 11, :host => "127.0.0.1", :port => 6379))
|
22
|
+
|
23
|
+
== Usage
|
24
|
+
* cache_for - Use this to tell the widget how long it should be cached for. Defaults to 1 hour
|
25
|
+
* cache_with - These are the widget parameters you want to use to build the cache key
|
26
|
+
* expire! - Expire the instances of a widget matching the given parameters
|
27
|
+
|
28
|
+
class Bluth < Erector::Widget
|
29
|
+
cache_with :name, :mistake
|
30
|
+
cache_for 3.seasons
|
31
|
+
|
32
|
+
def content
|
33
|
+
div "My name is #{@name} and #{@mistake.to_param}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Mistake < ORM::Base
|
38
|
+
attr_reader :updated_at
|
39
|
+
|
40
|
+
def initialize(size)
|
41
|
+
@size = size || :huge
|
42
|
+
@updated_at = Time.now
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
@size
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_param
|
50
|
+
"I_just_made_a_#{size}_mistake"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
=== cache_with
|
55
|
+
|
56
|
+
In the simple case the cache key will be built off of the value of the parameter eg.
|
57
|
+
|
58
|
+
widget Bluth, :name => "George Michael", :mistake => "consubrinaphilia"
|
59
|
+
|
60
|
+
This will yield a cache key of <em>"Lawnchair:Bluth:name:GeorgeMichael:mistake:consubrinaphilia"</em>
|
61
|
+
---
|
62
|
+
You can also pass whole objects into the widget and build the cache based on this. It will default to using the to_param of the object as the key component value.
|
63
|
+
|
64
|
+
@mistake = Mistake.create(:huge)
|
65
|
+
widget Bluth, :name => "Gob", :mistake => @mistake
|
66
|
+
|
67
|
+
This will yield a cache key of <em>"Lawnchair:Bluth:name:Gob:mistake:I_just_made_a_huge_mistake"</em>
|
68
|
+
---
|
69
|
+
This is essentially the same as doing this, which opens up more complex possibilities for generating cache keys
|
70
|
+
|
71
|
+
class Bluth < Erector::Widget
|
72
|
+
cache_with :name, :mistake => lambda {|mistake| mistake.to_param }
|
73
|
+
end
|
74
|
+
|
75
|
+
@mistake = Mistake.create(:huge)
|
76
|
+
widget Bluth, :name => "Gob", :mistake => @mistake
|
77
|
+
---
|
78
|
+
Using this, we could set the cache to auto expire every time the associated object is updated.
|
79
|
+
|
80
|
+
class Bluth < Erector::Widget
|
81
|
+
cache_with :name, :mistake => lambda {|mistake| mistake.updated_at }
|
82
|
+
end
|
83
|
+
|
84
|
+
== Expiration
|
85
|
+
|
86
|
+
Widget expiration is possible by calling the widget class's expire! method and passing in as much information about the keys to expire as you want.
|
87
|
+
|
88
|
+
Assume the following have occurred:
|
89
|
+
|
90
|
+
widget Bluth, :name => "Tobias", :mistake => "I_just_blue_myself"
|
91
|
+
widget Bluth, :name => "Tobias", :mistake => "analyst_and_therapist"
|
92
|
+
widget Bluth, :name => "Buster", :mistake => "swimming_with_seal"
|
93
|
+
|
94
|
+
You can expire all Bluth widgets regardless of what the values of the params passed into them with:
|
95
|
+
|
96
|
+
Bluth.expire!
|
97
|
+
|
98
|
+
You can expire only the Bluth widget with <em>:mistake => "I_just_blue_myself"</em> by using:
|
99
|
+
|
100
|
+
Bluth.expire!(:mistake => "I_just_blue_myself")
|
101
|
+
|
102
|
+
You can expire all widgets with <em>:name => "Tobias"</em> with:
|
103
|
+
|
104
|
+
Bluth.expire!(:name => "Tobias")
|
105
|
+
|
106
|
+
Likewise, calling the following will expire only the one cached version of the widget that exists, leaving the other instance in the cache:
|
107
|
+
|
108
|
+
Bluth.expire!(:name => "Tobias", :mistake => "I_just_blue_myself")
|
109
|
+
|
110
|
+
Any cache key component that is not passed into the expire! method will result in a wildcard match on that component, allowing you to be as specific as you wish.
|
111
|
+
|
112
|
+
<em>Note:
|
113
|
+
Lawnchair will automatically condense spaces, so don't feel constrained to using underscores or dashes in keys.</em>
|
114
|
+
|
115
|
+
|
116
|
+
....:~~~~~~~~~~~~~:~~::::::,..
|
117
|
+
......,~===~=====~~~~~::::::::::::::,..... ..
|
118
|
+
....,~+++=++++++==~~~~:::::::::::::::,... ..
|
119
|
+
..~I?+?????+?+++===~~~~::::::::::::::~:,... .
|
120
|
+
.=I7?I?????+?+++===~~~~~:::::::::::::~~:.... ..
|
121
|
+
.....~$$77II7III?+?++++===~~~~::::::::::::::~~=:......
|
122
|
+
....:ZZ$$7IIIIII???++++++==~~~:::::::::~~~:~~~==,.....
|
123
|
+
....7OZZ$77I777I????+++++==~~::::::::::~~::~~~===, ..
|
124
|
+
...?OOOZ$$$7777II?????+++===~~:::::::::::::~~~~==~....
|
125
|
+
..,7OOO$$$$$7777II??+++==~~~~~::::::::::::~::::~~=,...
|
126
|
+
. ?OOOOZZ$$$77777I??++=++=~~~~:::::::::::::::~~===:...
|
127
|
+
..I8OOO$Z$ZZ77777I???+=+==~~::::::::::,:::::~=+++++...
|
128
|
+
,78OOO$ZZZ$$7777II7ZOOOOZ$7?+~~::::,,,::~~~?I7ZOOZ?..... ..
|
129
|
+
,7O8OO$$ZZZ$77$77ZOO8OOZ$II?+++=::,,,:::~===~+++I$Z:.... ..
|
130
|
+
:7O88O8Z$$$$$$$OOZ???+III777$?+=~~::::::~:=I7+=::~+:~~, ..
|
131
|
+
,7OOO8OOZ77$I$OZIII~~~~=+???++I7I=:~=~=+I$=~I~=~:~+...=,:,
|
132
|
+
..IOOO8OOZ777IZZ+=I++++?+=??I7II7$Z$??I$$$+?+=::~~=:.. ,=?:
|
133
|
+
..?O88O88OZ$$$$7$Z+?+?77ZOO7III$7$ZI=:::Z7+78ZO8$I~=~++,~=..
|
134
|
+
..+O88O8OOZ$777=$7=??$ODN$8?+$I?7787=~~:O$?ZN88$Z8?=~...+:..
|
135
|
+
,:+7ZDDD8OZZ$$7?$Z?IZOII$7?++++?77$??+~:IZ=?+~~=+II=,...+,.
|
136
|
+
.....:II++7O8DOZ$$7$7IIZ??7Z7?~~=+++=+7O7+I?=:+$~=?7I??I?+:..:+..
|
137
|
+
... .?ZOZ?++$8O$$7777??7$=???I?+===~:~77+I?==~:~=~~~~~~~~==.,:..
|
138
|
+
... ,+77?7OI78O777777II+?$=~~~~~~~:::II+$7?+~:~:~~~:,:::::~=:.....
|
139
|
+
....,+77==Z$$8O$7777IIII??I=:::::,,+?II?77I+~,,::=I7~,,.:=++:....
|
140
|
+
.....=7?=?O8$88Z$$$777II?+=+7$IIII=:+$7III77?==~~=+=+?+=~~~~:.....
|
141
|
+
.....~7++7877O8O$$$$77I?+===:~~:::~+IZ$I?+7O$+=~~?++==~::::~:....
|
142
|
+
.....,I+?==?788OZZ$$77II?+==~~~~~===+7ODD8OZ8OZZ8D7+~~++~~~=: ...
|
143
|
+
......I=+=+I7O8OOZZ$777I??+===~~====+?IOO$7$O88Z$$7+=~=+=~==:.....
|
144
|
+
,$++7ZIOD8OZ$$$7777I?++=====?I$ZZZ$Z77ZZOOZ$ZZ$I+~+++=.....
|
145
|
+
~I++?7OO$$$$$$777$77?++=?IZOZOOOOZZOOOOOOZ$ZOZ$Z$+=+~......
|
146
|
+
.,?++?IZO$$Z$$$777777I??I$ZOOOOOOOZZOZZ7II$7IZOOOZI=+~......
|
147
|
+
..,II=:?Z$$$$$$77I77I?78888888OZZZ$77$III7?+?$O8OO$++,.. .
|
148
|
+
...,,..,7$$$$$$77I7777O8O8D888OZ?II:===?=,:.?NNOZO7++,..
|
149
|
+
........?7$$$$$77II77II=+77Z8NNNNDNNN8DNDNMNO7+?7I++~. .
|
150
|
+
........?$$$$$$$7I777I?==+++?IO8OZI==,::,?$7I?==?+==:
|
151
|
+
.....?7$$$$Z$77I7$$7?=++++I??7I+===+?+=?I?===~=+=..
|
152
|
+
..?$$ZZZZ$$$77777I?+=+++II++++=====++===~~==+...
|
153
|
+
. ?$$$ZZZZ$$777777I+=+++?II?+????++?+++=~~==~...
|
154
|
+
. . ..I$$ZZOOOZZ$$777777+=+?+=+?++++==+=~~~~~~~~...
|
155
|
+
.......:$$ZZZOOOOOZZ$777$$?+=+++===~~=~~~~~~~~~~=, ..
|
156
|
+
.....,I$7$$$$$ZOOOOZ$$7$Z7I+=====~~:::~:~~~~~=~.....
|
157
|
+
. ....+77777$$$ZOO88OZZ$$Z$I?+=====~~::~~~~~=~=,.. ..
|
158
|
+
. .,, ......,I77$$7I7777$$ZO888OOZOO$I?+++==~::~~:~=~+~ . . ..
|
159
|
+
. :D88DDDZ7+:.,?7I7$$$7IIIII777$ZOOO888OOZ$II??+====+==++,.
|
160
|
+
..?8Z8O88DDDDO7I??777IIIII?77I7$$ZOOOOOOOOZ$$7I?+===+???,..
|
161
|
+
,Z8OOOOOO888888DD8DDD88DDD$?IIII7$ZOZOOOOOOOOZZZZZ$Z$I=.....
|
14
162
|
|
15
163
|
== Copyright
|
16
164
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/erector_cache/widget.rb
CHANGED
@@ -71,7 +71,7 @@ module ErectorCache
|
|
71
71
|
if self.class.key_components.blank?
|
72
72
|
_render_via_without_caching(parent, options)
|
73
73
|
else
|
74
|
-
options = {:expire_in => @expire_in || 1.hour}
|
74
|
+
options = {:expire_in => @expire_in || 1.hour, :raw => true}
|
75
75
|
cached_fragment = LAWNCHAIR.cache(cache_key, options) do
|
76
76
|
parent.capture { _render_via_without_caching(parent, options) }
|
77
77
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erector_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grockit
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-08 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|