flagpole_sitta 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -112,9 +112,7 @@ module FlagpoleSitta
112
112
  for i in 0..flag[:space] do
113
113
  array_key = array_cache_key_gen i, route_id
114
114
  hash = FlagpoleSitta::CommonFs.flagpole_cache_read(array_key)
115
- if hash
116
- yield hash
117
- end
115
+ yield hash
118
116
  end
119
117
  end
120
118
 
@@ -125,63 +123,40 @@ module FlagpoleSitta
125
123
  #Nukes all corresponding caches for a given array.
126
124
  def destroy_array_cache options={}
127
125
 
128
- i = 0
129
-
130
126
  each_cache options[:route_id] do |hash|
131
- #A Check in Case there is some type of cache failure
132
- if hash.present?
133
- #If it has no scope, or it falls in scope
134
- if hash[:scope].nil? || options[:obj].in_scope(hash[:scope])
135
- #Get all the associated.
136
- associated = FlagpoleSitta::CommonFs.flagpole_cache_read(hash[:key])[:associated]
137
- puts hash[:key]
138
- #Destroy the actually cache
139
- FlagpoleSitta::CommonFs.flagpole_cache_delete(hash[:key])
140
- associated.each do |a|
141
- #Get the base key
142
- base_key = a.gsub(/\/[^\/]*\z/, "")
143
- #Get the flag. Capture the god damn flag!
144
- flag_key = base_key + "/Flag"
145
- #Get its location in the 'Array'
146
- n = a.split("/").last
147
- # Check in case of cache failure
148
- if flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
149
- #Add an empty spot to the 'Array'
150
- flag[:empty] = flag[:empty] + 1
151
- empty_stack_key = base_key + "/EmptyStack/" + flag[:empty].to_s
152
- #Save the empty spot location to the 'Stack'
153
- FlagpoleSitta::CommonFs.flagpole_cache_write(empty_stack_key, n)
154
- #Update the flag
155
- FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
156
- end
157
-
158
- #Finally get rid of the associated cache object.
159
- FlagpoleSitta::CommonFs.flagpole_cache_delete(a)
160
-
127
+ #A Check in Case there is some type of cache failure, or it is an empty spot, also if it has no scope, or it falls in scope
128
+ if hash.present? && (hash[:scope].nil? || options[:obj].in_scope(hash[:scope]))
129
+ #Get all the associated.
130
+ associated = FlagpoleSitta::CommonFs.flagpole_cache_read(hash[:key])[:associated]
131
+ Rails.logger.info "#{hash[:key]} is being cleared"
132
+ #Destroy the actually cache
133
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(hash[:key])
134
+ #The associated objects will always include the object we got the actually cache from
135
+ associated.each do |a|
136
+ #Get the base key
137
+ base_key = a.gsub(/\/[^\/]*\z/, "")
138
+ #Get the flag. Capture the god damn flag!
139
+ flag_key = base_key + "/Flag"
140
+ #Get its location in the 'Array'
141
+ n = a.split("/").last
142
+ # Check in case of cache failure
143
+ if flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
144
+ #Add an empty spot to the 'Array'
145
+ flag[:empty] = flag[:empty] + 1
146
+ empty_stack_key = base_key + "/EmptyStack/" + flag[:empty].to_s
147
+ #Save the empty spot location to the 'Stack'
148
+ FlagpoleSitta::CommonFs.flagpole_cache_write(empty_stack_key, n)
149
+ #Update the flag
150
+ FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
161
151
  end
162
- #Else It is not in scope so the cache lives to fight another day!
163
- else
164
- key = array_cache_key_gen i, options[:route_id]
165
- FlagpoleSitta::CommonFs.flagpole_cache_write(key, hash)
166
- i = i + 1
152
+
153
+ #Finally get rid of the associated cache object.
154
+ FlagpoleSitta::CommonFs.flagpole_cache_delete(a)
167
155
  end
156
+ #Else It is not in scope so the cache lives to fight another day!
168
157
  end
169
158
  end
170
159
 
171
-
172
- flag_key = array_cache_key_gen "Flag", options[:route_id]
173
- #If everything was deleted destroy the flag.
174
- if i == 0
175
- FlagpoleSitta::CommonFs.flagpole_cache_delete(flag_key)
176
- #Else update the flag
177
- else
178
- flag = FlagpoleSitta::CommonFs.flagpole_cache_read(flag_key)
179
- flag[:space] = (i - 1)
180
- #Sense we moved through every object and moved all the remaining objects down
181
- #there should be no empty spaces.
182
- flag[:empty] = -1
183
- FlagpoleSitta::CommonFs.flagpole_cache_write(flag_key, flag)
184
- end
185
160
  end
186
161
 
187
162
  end
@@ -224,10 +199,15 @@ module FlagpoleSitta
224
199
 
225
200
  #AR - For Safety this will not recurse upwards for the extra cache maintenance
226
201
  extra_cache_maintenance(alive)
227
- rescue
202
+ rescue Exception => e
228
203
  #Keep ending up with one of the array objects having a key of nil. Despite the fact that it would have to at least start with /view
229
204
  #becuase of the way its set up in the helper. If that happens all bets are off and just clear everything.
230
205
  Rails.cache.clear
206
+ Rails.logger.error("CACHE FAILURE @BEFORE STATE CHANGE CACHE IS BEING NUKED :: FLAGPOLE_SITTA")
207
+ Rails.logger.error(e.message)
208
+ e.backtrace.inspect.each do |b|
209
+ Rails.logger.error(b)
210
+ end
231
211
  end
232
212
 
233
213
  end
@@ -236,16 +216,26 @@ module FlagpoleSitta
236
216
  #saved fits into any cache's scope. The above call to clear index caches is basically the object_was call, while this is just the call
237
217
  #for the update object.
238
218
  def post_cache_work
239
- original_clazz = self.class
240
- cur_clazz = original_clazz
219
+ begin
220
+ original_clazz = self.class
221
+ cur_clazz = original_clazz
241
222
 
242
- while(cur_clazz.respond_to? :destroy_array_cache)
243
- # AR - Remember to include models_in_index in your helper call in the corresponding index cache.
244
- cur_clazz.destroy_array_cache(:obj => self)
223
+ while(cur_clazz.respond_to? :destroy_array_cache)
224
+ # AR - Remember to include models_in_index in your helper call in the corresponding index cache.
225
+ cur_clazz.destroy_array_cache(:obj => self)
245
226
 
246
- cur_clazz = cur_clazz.superclass
227
+ cur_clazz = cur_clazz.superclass
228
+ end
229
+ rescue Exception => e
230
+ #Keep ending up with one of the array objects having a key of nil. Despite the fact that it would have to at least start with /view
231
+ #becuase of the way its set up in the helper. If that happens all bets are off and just clear everything.
232
+ Rails.cache.clear
233
+ Rails.logger.error("CACHE FAILURE @AFTER_SAVE CACHE IS BEING NUKED :: FLAGPOLE_SITTA")
234
+ Rails.logger.error(e.message)
235
+ e.backtrace.inspect.each do |b|
236
+ Rails.logger.error(b)
237
+ end
247
238
  end
248
-
249
239
  end
250
240
 
251
241
  #AR - For Safety this will not recurse upwards for the extra cache maintenance
@@ -1,3 +1,3 @@
1
1
  module FlagpoleSitta
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
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: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
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-09-19 00:00:00 Z
18
+ date: 2012-10-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: dalli