flagpole_sitta 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -14,13 +14,16 @@ The rottenness and evil in me.
14
14
 
15
15
  ===This gem should be considered in beta.
16
16
 
17
+ ===Before You Use read This.
18
+ https://github.com/rovermicrover/FlagpoleSitta/wiki/Before-You-Use-Read-This
19
+
17
20
  This gem was inspired in part by the song Flagpole Sitta by Harvey Danger. So if you like the gem and are wanting to help out please either donate your time and submit some patches, or donate to the band who wrote the song. They put there last two albums out there all open source like, only asking that those that could donate after downloading. While your donating, if you choose to do so, don't be afraid to download their albums, its good stuff!
18
21
 
19
22
  http://www.harveydanger.com/contribute.php
20
23
 
21
24
  My grammar ability's are fail. So if something doesn't make sense in the docs don't be afraid to point it out and/or submit a patch. Because to me it all looks right.....
22
25
 
23
- This gem has also only so far been tested with Memcache using the Dalli gem. File System caching and memory caching are not recommended. Redis/Memcache are defiantly suggested and strongly encouraged for this gem.
26
+ File System caching and memory caching are not recommended. Redis/Memcache are defiantly suggested and strongly encouraged for this gem. If your using a cloud solution redis more then memecached for reasons stated in the "Before you use read this." seciton of the wiki.
24
27
 
25
28
  == Inspiration
26
29
 
@@ -108,64 +108,73 @@ module FlagpoleSittaHelper
108
108
  "@" + (options[:section] ? options[:section] : 'body') + "_calls"
109
109
  )
110
110
 
111
- if hash = Rails.cache.read(key)
111
+ hash = benchmark("Read fragment #{key} :: FlagpoleSitta") do
112
+ hash = FlagpoleSitta::CommonFs.flagpole_cache_read(key)
113
+ end
114
+
115
+ if hash
112
116
  content = hash[:content]
113
117
  else
114
- #NOTE This is not safe for .builder xml files, and using capture here is why.
115
- #Its either this or a really complicated hack, from the rails source code, which
116
- #at the moment I don't feel comfortable using. Waiting for an official solution for
117
- #the ability to use capture with .builders.
118
- content = capture do
119
-
120
- if calls
121
- calls.each do |c|
122
- if instance_variable_get("@#{c[0]}").nil?
123
- instance_variable_set("@#{c[0]}", c[1].call())
118
+ content = benchmark("Write fragment #{key} :: FlagpoleSitta") do
119
+ #NOTE This is not safe for .builder xml files, and using capture here is why.
120
+ #Its either this or a really complicated hack, from the rails source code, which
121
+ #at the moment I don't feel comfortable using. Waiting for an official solution for
122
+ #the ability to use capture with .builders.
123
+ content = capture do
124
+
125
+ if calls
126
+ calls.each do |c|
127
+ if instance_variable_get("@#{c[0]}").nil?
128
+ instance_variable_set("@#{c[0]}", c[1].call())
129
+ end
124
130
  end
125
131
  end
126
- end
127
-
128
- yield
129
132
 
130
- end
131
-
132
- #AR - If the cache is an index or includes an index
133
- #then models_in_index should be passed with all the
134
- #models that could show up in the index.
135
- #Then on save of any model include here this index will be cleared.
136
- #This can also be used for fragments where there are just so many objects,
137
- #that while its not an index, there isn't a clear way expect to nuke it when
138
- #any of the model types involved are updated.
133
+ yield
139
134
 
140
- associated = Array.new
135
+ end
141
136
 
142
- if options[:models_in_index].class.eql?(Array)
143
- options[:models_in_index].each_index do |i|
144
- m = options[:models_in_index][i]
145
- if options[:scope]
146
- scope = options[:scope][i]
137
+ #AR - If the cache is an index or includes an index
138
+ #then models_in_index should be passed with all the
139
+ #models that could show up in the index.
140
+ #Then on save of any model include here this index will be cleared.
141
+ #This can also be used for fragments where there are just so many objects,
142
+ #that while its not an index, there isn't a clear way expect to nuke it when
143
+ #any of the model types involved are updated.
144
+
145
+ associated = Array.new
146
+
147
+ if options[:models_in_index].class.eql?(Array)
148
+ options[:models_in_index].each_index do |i|
149
+ m = options[:models_in_index][i]
150
+ if options[:scope]
151
+ scope = options[:scope][i]
152
+ end
153
+ processed_model = m.respond_to?(:constantize) ? m.constantize : m
154
+ associated << update_index_array_cache(processed_model, key, scope)
147
155
  end
148
- processed_model = m.respond_to?(:constantize) ? m.constantize : m
149
- associated << update_index_array_cache(processed_model, key, scope)
156
+ elsif options[:models_in_index]
157
+ processed_model = options[:models_in_index].respond_to?(:constantize) ? options[:models_in_index].constantize : options[:models_in_index]
158
+ associated << update_index_array_cache(processed_model, key, options[:scope])
150
159
  end
151
- elsif options[:models_in_index]
152
- processed_model = options[:models_in_index].respond_to?(:constantize) ? options[:models_in_index].constantize : options[:models_in_index]
153
- associated << update_index_array_cache(processed_model, key, options[:scope])
154
- end
155
160
 
156
- #AR - Create a link between each declared object and the cache.
161
+ #AR - Create a link between each declared object and the cache.
157
162
 
158
- if !options[:index_only] && options[:route_id]
159
- if options[:route_id].class.eql?(Array) && options[:model].class.eql?(Array)
160
- options[:model].each_index do |i|
161
- associated << update_show_array_cache(options[:model][i], key, options[:route_id][i])
163
+ if !options[:index_only] && options[:route_id]
164
+ if options[:route_id].class.eql?(Array) && options[:model].class.eql?(Array)
165
+ options[:model].each_index do |i|
166
+ associated << update_show_array_cache(options[:model][i], key, options[:route_id][i])
167
+ end
168
+ else
169
+ associated << update_show_array_cache(main_model, key, main_route_id)
162
170
  end
163
- else
164
- associated << update_show_array_cache(main_model, key, main_route_id)
165
171
  end
166
- end
167
172
 
168
- Rails.cache.write(key, {:content => content, :associated => associated})
173
+ FlagpoleSitta::CommonFs.flagpole_cache_write(key, {:content => content, :associated => associated})
174
+
175
+ content
176
+
177
+ end
169
178
 
170
179
  end
171
180
 
@@ -22,18 +22,31 @@ module FlagpoleSitta
22
22
 
23
23
  #After update destroy old cache and write new one.
24
24
  def br_update alive
25
+
25
26
  clazz = self.class
26
27
 
27
- Rails.cache.delete("#{clazz}/BracketRetrieval/#{self.send(self.class.key_field + "_was")}")
28
+ key = clazz.get_br_key(self.send(self.class.key_field + "_was"))
29
+
30
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(key)
28
31
 
29
32
  if alive
30
- Rails.cache.write("#{clazz}/BracketRetrieval/#{self.send(self.class.key_field)}", self.send(self.class.value_field))
33
+ key = clazz.get_br_key(self.send(self.class.key_field))
34
+ value = self.send(self.class.value_field)
35
+ FlagpoleSitta::CommonFs.flagpole_cache_write(key, value)
31
36
  end
32
37
 
33
38
  end
34
39
 
35
40
  module ClassMethods
36
41
 
42
+ def get_br_key key
43
+
44
+ clazz = self
45
+
46
+ "#{clazz}/BracketRetrieval/#{key}"
47
+
48
+ end
49
+
37
50
  #Will look up the object chain till it finds what it was set to, or not set too.
38
51
  def safe_content?
39
52
  result = @_safe_content || (self.superclass.respond_to?(:safe_content?) ? self.superclass.safe_content? : nil) || false
@@ -58,7 +71,7 @@ module FlagpoleSitta
58
71
  def [] key
59
72
  clazz = self
60
73
  #If its in cache return that, unless blank, then return nil.
61
- if value = Rails.cache.read("#{clazz}/BracketRetrieval/#{key}") || Rails.cache.exist?("#{clazz}/BracketRetrieval/#{key}")
74
+ if value = FlagpoleSitta::CommonFs.flagpole_cache_read(get_br_key(key)) || FlagpoleSitta::CommonFs.flagpole_cache_exist?(get_br_key(key))
62
75
  if value.present?
63
76
  value = self.safe_content? ? value.html_safe : value
64
77
  else
@@ -70,13 +83,13 @@ module FlagpoleSitta
70
83
  #Else if the object is in the database put it into the cache then return it.
71
84
  elsif obj = self.send("find_by_#{self.key_field}", key)
72
85
  value = obj.send(self.value_field)
73
- Rails.cache.write("#{clazz}/BracketRetrieval/#{key}", value)
86
+ FlagpoleSitta::CommonFs.flagpole_cache_write(get_br_key(key), value)
74
87
  value = value && self.safe_content? ? value.html_safe : value
75
88
  #Else create the corresponding object as blank, and return nil.
76
89
  #The last line there is why this extension should never be used with user generated content.
77
90
  else
78
91
  rec = self.create(self.key_field.to_sym => key, self.value_field.to_sym => self.default_value)
79
- Rails.cache.write("#{clazz}/BracketRetrieval/#{key}", rec.send(self.value_field))
92
+ FlagpoleSitta::CommonFs.flagpole_cache_write(get_br_key(key), rec.send(self.value_field))
80
93
  value = nil
81
94
  end
82
95
  value
@@ -16,6 +16,10 @@ module FlagpoleSitta
16
16
 
17
17
  module ClassMethods
18
18
 
19
+ def clazz
20
+ self
21
+ end
22
+
19
23
  #Determines if its for an index array or show array.
20
24
  def mid_key_gen route_id
21
25
  if route_id
@@ -25,29 +29,42 @@ module FlagpoleSitta
25
29
  end
26
30
  end
27
31
 
28
- #Creates the 'array' in the cache.
29
- def initialize_array_cache route_id = nil
32
+ #Options :emptystack will make it generate a key for the emptystack instead of the general cache array.
33
+ def array_cache_key_gen key, route_id, options={}
30
34
 
31
35
  mid_key = mid_key_gen route_id
32
36
 
33
- clazz = self
37
+ model = options[:model] || clazz
38
+
39
+
40
+ if options[:emptystack]
41
+ "#{model}/#{mid_key}/EmptyStack/#{key}"
42
+ else
43
+ "#{model}/#{mid_key}/#{key}"
44
+ end
45
+
46
+ end
47
+
48
+ #Creates the 'array' in the cache.
49
+ def initialize_array_cache route_id = nil
50
+
51
+ flag_key = array_cache_key_gen "Flag", route_id
34
52
 
35
53
  flag = {:space => -1, :empty => -1}
36
54
 
37
- Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
55
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
38
56
 
39
57
  flag
40
58
 
41
59
  end
42
60
 
43
61
  #Updates the 'array' in the cache.
62
+ #Options :route_id which determines the type of mid_key
44
63
  def update_array_cache key, options={}
45
64
 
46
- mid_key = mid_key_gen options[:route_id]
65
+ flag_key = array_cache_key_gen "Flag", options[:route_id]
47
66
 
48
- clazz = self
49
-
50
- flag = Rails.cache.read("#{clazz}/#{mid_key}/Flag")
67
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
51
68
 
52
69
  #AR - If it doesn't exist start the process of creating it
53
70
  if flag.nil?
@@ -56,9 +73,11 @@ module FlagpoleSitta
56
73
 
57
74
  if flag[:empty] > -1
58
75
  #Find any empty container to use by popping it off of the top of the "stack".
59
- i = Rails.cache.read("#{clazz}/#{mid_key}/EmptyStack/#{flag[:empty]}")
76
+ empty_key = array_cache_key_gen flag[:empty], options[:route_id], :emptystack => true
77
+
78
+ i = FlagpoleSitta::CommonFs.flagpole_cache_read(empty_key)
60
79
  #Sense its going to be used remove its reference from the Stack.
61
- Rails.cache.delete("#{clazz}/#{mid_key}/EmptyStack/#{flag[:empty]}")
80
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(empty_key)
62
81
  #Update the empty on flag to now hit the newest none used container on the stack.
63
82
  flag[:empty] = flag[:empty] - 1
64
83
  else
@@ -68,30 +87,31 @@ module FlagpoleSitta
68
87
  end
69
88
 
70
89
  #AR - write out the new index at the end of the array
71
- Rails.cache.write("#{clazz}/#{mid_key}/#{i}", {:key => key, :scope => options[:scope]})
90
+ array_key = array_cache_key_gen i, options[:route_id]
91
+ FlagpoleSitta::CommonFs.flagpole_cache_write(array_key, {:key => key, :scope => options[:scope]})
72
92
 
73
93
  #AR - update flag in the cache
74
- Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
94
+ flag_key = array_cache_key_gen "Flag", options[:route_id]
95
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
75
96
 
76
- "#{clazz}/#{mid_key}/#{i}"
97
+ key
77
98
 
78
99
  end
79
100
 
80
101
  #Loops through the array in the cache.
81
102
  def each_cache route_id = nil, &block
82
103
 
83
- mid_key = mid_key_gen route_id
84
-
85
- clazz = self
104
+ flag_key = array_cache_key_gen "Flag", route_id
86
105
 
87
- flag = Rails.cache.read("#{clazz}/#{mid_key}/Flag")
106
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
88
107
 
89
108
  #AR - If there aren't any index do nothing.
90
109
  #Else wise loop through every index.
91
110
  #If it actually does exist then yield.
92
111
  if flag
93
112
  for i in 0..flag[:space] do
94
- hash = Rails.cache.read("#{clazz}/#{mid_key}/#{i}")
113
+ array_key = array_cache_key_gen i, route_id
114
+ hash = FlagpoleSitta::CommonFs.flagpole_cache_read(array_key)
95
115
  if hash
96
116
  yield hash
97
117
  end
@@ -105,10 +125,6 @@ module FlagpoleSitta
105
125
  #Nukes all corresponding caches for a given array.
106
126
  def destroy_array_cache options={}
107
127
 
108
- mid_key = mid_key_gen options[:route_id]
109
-
110
- clazz = self
111
-
112
128
  i = 0
113
129
 
114
130
  each_cache options[:route_id] do |hash|
@@ -117,9 +133,10 @@ module FlagpoleSitta
117
133
  #If it has no scope, or it falls in scope
118
134
  if hash[:scope].nil? || options[:obj].in_scope(hash[:scope])
119
135
  #Get all the associated.
120
- associated = Rails.cache.read(hash[:key])[:associated]
136
+ associated = FlagpoleSitta::CommonFs.flagpole_cache_read(hash[:key])[:associated]
137
+ puts hash[:key]
121
138
  #Destroy the actually cache
122
- Rails.cache.delete(hash[:key])
139
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(hash[:key])
123
140
  associated.each do |a|
124
141
  #Get the base key
125
142
  base_key = a.gsub(/\/[^\/]*\z/, "")
@@ -128,39 +145,42 @@ module FlagpoleSitta
128
145
  #Get its location in the 'Array'
129
146
  n = a.split("/").last
130
147
  # Check in case of cache failure
131
- if flag = Rails.cache.read(flag_key)
148
+ if flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
132
149
  #Add an empty spot to the 'Array'
133
150
  flag[:empty] = flag[:empty] + 1
134
151
  empty_stack_key = base_key + "/EmptyStack/" + flag[:empty].to_s
135
152
  #Save the empty spot location to the 'Stack'
136
- Rails.cache.write(empty_stack_key, n)
153
+ FlagpoleSitta::CommonFs.flagpole_cache_write(empty_stack_key, n)
137
154
  #Update the flag
138
- Rails.cache.write(flag_key, flag)
155
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
139
156
  end
140
157
 
141
158
  #Finally get rid of the associated cache object.
142
- Rails.cache.delete(a)
159
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(a)
143
160
 
144
161
  end
145
162
  #Else It is not in scope so the cache lives to fight another day!
146
163
  else
147
- Rails.cache.write("#{clazz}/#{mid_key}/#{i}", hash)
164
+ key = array_cache_key_gen i, options[:route_id]
165
+ FlagpoleSitta::CommonFs.flagpole_cache_write(key, hash)
148
166
  i = i + 1
149
167
  end
150
168
  end
151
169
  end
152
170
 
171
+
172
+ flag_key = array_cache_key_gen "Flag", options[:route_id]
153
173
  #If everything was deleted destroy the flag.
154
174
  if i == 0
155
- Rails.cache.delete("#{clazz}/#{mid_key}/Flag")
175
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(flag_key)
156
176
  #Else update the flag
157
177
  else
158
- flag = Rails.cache.read("#{clazz}/#{mid_key}/Flag")
178
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
159
179
  flag[:space] = (i - 1)
160
180
  #Sense we moved through every object and moved all the remaining objects down
161
181
  #there should be no empty spaces.
162
182
  flag[:empty] = -1
163
- Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
183
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
164
184
  end
165
185
  end
166
186
 
@@ -184,21 +204,21 @@ module FlagpoleSitta
184
204
  # Also have to go through all its super objects till the super objects aren't cache sittaed
185
205
  # this is because the new updated object for a sub class, could have also been in a cache for
186
206
  # said sub class, but also in a cache for its super.
187
- clazz = original_clazz
188
- while(clazz.respond_to? :destroy_array_cache)
207
+ cur_clazz = original_clazz
208
+ while(cur_clazz.respond_to? :destroy_array_cache)
189
209
 
190
210
  #AR - Clear all caches related to the old route_id
191
- clazz.destroy_array_cache(:route_id => self.try(:send, ("#{clazz.route_id}_was")).to_s)
211
+ cur_clazz.destroy_array_cache(:route_id => self.try(:send, ("#{cur_clazz.route_id}_was")).to_s)
192
212
  #AR - Clear all caches related to the new route_id just in case
193
- clazz.destroy_array_cache(:route_id => self.try(:send, ("#{clazz.route_id}")).to_s)
213
+ cur_clazz.destroy_array_cache(:route_id => self.try(:send, ("#{cur_clazz.route_id}")).to_s)
194
214
  #AR - If the new and old are the same All that will happen on the second call is that
195
215
  #it will write the flag out and then destroy it. A very tiny bit of work
196
216
  #for a great amount of extra protection.
197
217
 
198
218
  # AR - Remember to include models_in_index in your helper call in the corresponding index cache.
199
- clazz.destroy_array_cache(:obj => self)
219
+ cur_clazz.destroy_array_cache(:obj => self)
200
220
 
201
- clazz = clazz.superclass
221
+ cur_clazz = cur_clazz.superclass
202
222
  end
203
223
 
204
224
  #AR - For Safety this will not recurse upwards for the extra cache maintenance
@@ -211,13 +231,13 @@ module FlagpoleSitta
211
231
  #for the update object.
212
232
  def post_cache_work
213
233
  original_clazz = self.class
214
- clazz = original_clazz
234
+ cur_clazz = original_clazz
215
235
 
216
- while(clazz.respond_to? :destroy_array_cache)
236
+ while(cur_clazz.respond_to? :destroy_array_cache)
217
237
  # AR - Remember to include models_in_index in your helper call in the corresponding index cache.
218
- clazz.destroy_array_cache(:obj => self)
238
+ cur_clazz.destroy_array_cache(:obj => self)
219
239
 
220
- clazz = clazz.superclass
240
+ cur_clazz = cur_clazz.superclass
221
241
  end
222
242
 
223
243
  end
@@ -0,0 +1,30 @@
1
+ module FlagpoleSitta
2
+
3
+ class CommonFs
4
+
5
+ class << self
6
+
7
+ def app_hash_namespace
8
+ "#{Rails.application.class.to_s.split("::").first}/#{Rails.env}/"
9
+ end
10
+
11
+ def flagpole_cache_read key
12
+ Rails.cache.read(app_hash_namespace + key.to_s)
13
+ end
14
+
15
+ def flagpole_cache_write key, value
16
+ Rails.cache.write(app_hash_namespace + key.to_s, value)
17
+ end
18
+
19
+ def flagpole_cache_delete key
20
+ Rails.cache.delete(app_hash_namespace + key.to_s)
21
+ end
22
+
23
+ def flagpole_cache_exist? key
24
+ Rails.cache.exist?(app_hash_namespace + key.to_s)
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ end
@@ -12,6 +12,31 @@ module FlagpoleSitta
12
12
 
13
13
  module ClassMethods
14
14
 
15
+ #Options :emptystack will make it generate a key for the emptystack instead of the general cache array.
16
+ def eh_key_gen key, options={}
17
+
18
+ superclazz = get_super_with_existence_hash
19
+
20
+ end_key = end_key_gen key, options[:class]
21
+
22
+
23
+ if options[:emptystack]
24
+ "#{superclazz}/ExistenceHash/EmptyStack/#{end_key}"
25
+ else
26
+ "#{superclazz}/ExistenceHash/#{end_key}"
27
+ end
28
+
29
+ end
30
+
31
+ def end_key_gen key, clazz
32
+ if clazz
33
+ "#{clazz}/#{key}"
34
+ else
35
+ "#{key}"
36
+ end
37
+ end
38
+
39
+
15
40
  #Creates the 'hash' in the cache.
16
41
  def initialize_existence_hash
17
42
 
@@ -23,12 +48,15 @@ module FlagpoleSitta
23
48
 
24
49
  flag = {:space => (count - 1), :count => count, :empty => -1}
25
50
 
26
- Rails.cache.write("#{superclazz}/ExistenceHash/Flag", flag)
51
+ flag_key = eh_key_gen "Flag"
52
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
27
53
  i = 0
28
54
  superclazz.find_each do |m|
29
55
  #Route ID is the key. The POS is used to emulate an array, along with the length stored in the flag.
30
- Rails.cache.write("#{superclazz}/ExistenceHash/#{m.class}/#{m.send(m.class.route_id).to_s}", {:type => m.class.to_s, :pos => i, :num => m.has_attribute?('num') ? (m.num || 0) : 0})
31
- Rails.cache.write("#{superclazz}/ExistenceHash/#{i}", {:key => m.send(m.class.route_id).to_s, :type => m.class.to_s})
56
+ main_key = eh_key_gen m.send(m.class.route_id), :class => m.class
57
+ FlagpoleSitta::CommonFs.flagpole_cache_write(main_key, {:type => m.class.to_s, :pos => i, :num => m.has_attribute?('num') ? (m.num || 0) : 0})
58
+ array_key = eh_key_gen i
59
+ FlagpoleSitta::CommonFs.flagpole_cache_write(array_key, {:key => m.send(m.class.route_id).to_s, :type => m.class.to_s})
32
60
  i = i + 1
33
61
  end
34
62
 
@@ -43,13 +71,15 @@ module FlagpoleSitta
43
71
 
44
72
  superclazz = get_super_with_existence_hash
45
73
  #Try to find the hash
46
- flag = Rails.cache.read("#{superclazz}/ExistenceHash/Flag")
74
+ flag_key = eh_key_gen "Flag"
75
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
47
76
  #If it doesn't exist start the process of creating it
48
77
  if flag.nil?
49
78
  initialize_existence_hash
50
79
  end
51
80
 
52
- Rails.cache.read("#{superclazz}/ExistenceHash/#{clazz}/#{key}")
81
+ main_key = eh_key_gen key, :class => clazz
82
+ FlagpoleSitta::CommonFs.flagpole_cache_read(main_key)
53
83
 
54
84
  end
55
85
 
@@ -65,7 +95,8 @@ module FlagpoleSitta
65
95
  #Update the hash key if it exists
66
96
  if hash
67
97
  hash[:num] = hash[:num] + 1
68
- Rails.cache.write("#{superclazz}/ExistenceHash/#{clazz}/#{key}", hash)
98
+ main_key = eh_key_gen key, :class => clazz
99
+ FlagpoleSitta::CommonFs.flagpole_cache_write(main_key, hash)
69
100
  end
70
101
 
71
102
  #Return the value
@@ -80,7 +111,8 @@ module FlagpoleSitta
80
111
 
81
112
  superclazz = get_super_with_existence_hash
82
113
 
83
- flag = Rails.cache.read("#{superclazz}/ExistenceHash/Flag")
114
+ flag_key = eh_key_gen "Flag"
115
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
84
116
 
85
117
  if flag.nil?
86
118
  flag = initialize_existence_hash
@@ -89,10 +121,12 @@ module FlagpoleSitta
89
121
  unless flag[:count] == 0
90
122
  for i in 0..flag[:space] do
91
123
 
92
- value = Rails.cache.read("#{superclazz}/ExistenceHash/#{i}")
124
+ cur_array_key = eh_key_gen i
125
+ value = FlagpoleSitta::CommonFs.flagpole_cache_read(cur_array_key)
93
126
 
94
127
  if value.present? && value[:type].to_s.eql?(clazz.to_s)
95
- hash = Rails.cache.read("#{superclazz}/ExistenceHash/#{value[:type]}/#{value[:key]}")
128
+ cur_main_key = eh_key_gen value[:key], :class => value[:type]
129
+ hash = FlagpoleSitta::CommonFs.flagpole_cache_read(cur_main_key)
96
130
  #This if statement is to make it fail gracefully if the cache has degraded.
97
131
  if hash.present?
98
132
  yield value[:key], hash
@@ -149,7 +183,11 @@ module FlagpoleSitta
149
183
  new_key = new_clazz.respond_to?(:constantize) ? self.send("#{new_clazz.constantize.route_id}") : nil
150
184
  old_key = old_clazz.respond_to?(:constantize) ? self.send("#{old_clazz.constantize.route_id}_was") : nil
151
185
 
152
- flag = Rails.cache.read("#{superclazz}/ExistenceHash/Flag")
186
+ new_main_key = superclazz.eh_key_gen new_key, :class => new_clazz
187
+ old_main_key = superclazz.eh_key_gen old_key, :class => old_clazz
188
+
189
+ flag_key = superclazz.eh_key_gen "Flag"
190
+ flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
153
191
 
154
192
  if flag.nil?
155
193
  flag = self.class.initialize_existence_hash
@@ -161,9 +199,10 @@ module FlagpoleSitta
161
199
  #if there are empty containers use them
162
200
  if flag[:empty] > -1
163
201
  #Find any empty container to use by popping it off of the top of the "stack".
164
- i = Rails.cache.read("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}")
202
+ empty_key = superclazz.eh_key_gen flag[:empty], :emptystack => true
203
+ i = FlagpoleSitta::CommonFs.flagpole_cache_read(empty_key)
165
204
  #Sense its going to be used remove its reference from the Stack.
166
- Rails.cache.delete("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}")
205
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(empty_key)
167
206
  #Update the empty on flag to now hit the newest none used container on the stack.
168
207
  flag[:empty] = flag[:empty] - 1
169
208
  #Else add a space to the end.
@@ -175,30 +214,33 @@ module FlagpoleSitta
175
214
  hash = {:type => new_clazz, :num => self.has_attribute?('num') ? (self.num || 0) : 0, :pos => i}
176
215
  #If its an already existing record them get its existence hash, and then remove it from the cache.
177
216
  else
178
- hash = Rails.cache.read("#{superclazz}/ExistenceHash/#{old_clazz}/#{old_key}")
217
+ hash = FlagpoleSitta::CommonFs.flagpole_cache_read(old_main_key)
179
218
  hash[:type] = new_clazz
180
219
  end
181
220
 
221
+ array_main_key = superclazz.eh_key_gen hash[:pos]
222
+
182
223
  #Before new info gets written make sure to delete all the old records just in case. The New location before it gets used too.
183
- Rails.cache.delete("#{superclazz}/ExistenceHash/#{new_clazz}/#{new_key}")
184
- Rails.cache.delete("#{superclazz}/ExistenceHash/#{old_clazz}/#{old_key}")
185
- Rails.cache.delete("#{superclazz}/ExistenceHash/#{hash[:pos]}")
224
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(new_main_key)
225
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(old_main_key)
226
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(array_main_key)
186
227
 
187
228
  #If the record is not being destroyed add new route_id to existence hash
188
229
  if alive
189
- Rails.cache.write("#{superclazz}/ExistenceHash/#{new_clazz}/#{new_key}", hash)
190
- Rails.cache.write("#{superclazz}/ExistenceHash/#{hash[:pos]}", {:type => new_clazz, :key => new_key})
230
+ FlagpoleSitta::CommonFs.flagpole_cache_write(new_main_key, hash)
231
+ FlagpoleSitta::CommonFs.flagpole_cache_write(array_main_key, {:type => new_clazz, :key => new_key})
191
232
  else
192
233
  if hash[:pos] == flag[:space]
193
234
  flag[:space] = flag[:space] - 1
194
235
  else
195
236
  flag[:empty] = flag[:empty] + 1
196
- Rails.cache.write("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}", hash[:pos])
237
+ empty_key = superclazz.eh_key_gen flag[:empty], :emptystack => true
238
+ FlagpoleSitta::CommonFs.flagpole_cache_write(empty_key, hash[:pos])
197
239
  end
198
240
  flag[:count] = flag[:count] - 1
199
241
  end
200
242
 
201
- Rails.cache.write("#{superclazz}/ExistenceHash/Flag", flag)
243
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
202
244
 
203
245
  end
204
246
 
@@ -1,3 +1,3 @@
1
1
  module FlagpoleSitta
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.4"
3
3
  end
@@ -8,9 +8,9 @@ module FlagpoleSitta
8
8
  yield self
9
9
  end
10
10
 
11
-
12
11
  end
13
12
 
13
+ require 'flagpole_sitta/common_fs'
14
14
  require 'flagpole_sitta/bracket_retrieval'
15
15
  require 'flagpole_sitta/cache_sitta'
16
16
  require 'flagpole_sitta/existence_hash'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flagpole_sitta
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Rove (Rover)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-21 00:00:00 Z
18
+ date: 2012-08-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: dalli
@@ -55,6 +55,7 @@ files:
55
55
  - lib/flagpole_sitta.rb
56
56
  - lib/flagpole_sitta/bracket_retrieval.rb
57
57
  - lib/flagpole_sitta/cache_sitta.rb
58
+ - lib/flagpole_sitta/common_fs.rb
58
59
  - lib/flagpole_sitta/config_sitta.rb
59
60
  - lib/flagpole_sitta/controller_sitta.rb
60
61
  - lib/flagpole_sitta/engine.rb