flagpole_sitta 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.require_path = 'lib'
16
16
 
17
17
  #Dependencies
18
+ #This is just for now until I can test it with out adapters.
18
19
  s.add_dependency('dalli')
19
20
 
20
21
  end
@@ -27,8 +27,8 @@ module FlagpoleSitta
27
27
  i = 0
28
28
  superclazz.find_each do |m|
29
29
  #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.has_attribute?('type') ? m.type : m.class, :pos => i, :num => m.has_attribute?('num') ? m.num : 0})
31
- Rails.cache.write("#{superclazz}/ExistenceHash/#{i}", {:key => m.send(m.class.route_id).to_s, :type => m.class})
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})
32
32
  i = i + 1
33
33
  end
34
34
 
@@ -91,9 +91,12 @@ module FlagpoleSitta
91
91
 
92
92
  value = Rails.cache.read("#{superclazz}/ExistenceHash/#{i}")
93
93
 
94
- if value.present? && value[:type].eql?(clazz)
94
+ if value.present? && value[:type].to_s.eql?(clazz.to_s)
95
95
  hash = Rails.cache.read("#{superclazz}/ExistenceHash/#{value[:type]}/#{value[:key]}")
96
- yield value[:key], hash
96
+ #This if statement is to make it fail gracefully if the cache has degraded.
97
+ if hash.present?
98
+ yield value[:key], hash
99
+ end
97
100
  end
98
101
 
99
102
  end
@@ -138,13 +141,13 @@ module FlagpoleSitta
138
141
  #Get the Current Class and the Old Class in case the object changed classes.
139
142
  #If its the base object, ie type is nil, then return class as the old_clazz.
140
143
  #If the object doesn't have the type field assume it can't change classes.
141
- new_clazz = self.has_attribute?('type') ? (self.type || self.class) : self.class
142
- old_clazz = self.has_attribute?('type') ? (self.type_was || self.class) : self.class
144
+ new_clazz = self.has_attribute?('type') ? (self.type || self.class.to_s) : self.class.to_s
145
+ old_clazz = self.has_attribute?('type') ? (self.type_was || self.class.to_s) : self.class.to_s
143
146
  superclazz = self.class.get_super_with_existence_hash
144
147
 
145
148
  #Old key is where it was, and new is where it is going.
146
- old_key = self.send("#{self.class.route_id}_was")
147
- new_key = self.send("#{self.class.route_id}")
149
+ new_key = new_clazz.respond_to?(:constantize) ? self.send("#{new_clazz.constantize.route_id}") : nil
150
+ old_key = old_clazz.respond_to?(:constantize) ? self.send("#{old_clazz.constantize.route_id}_was") : nil
148
151
 
149
152
  flag = Rails.cache.read("#{superclazz}/ExistenceHash/Flag")
150
153
 
@@ -169,20 +172,23 @@ module FlagpoleSitta
169
172
  flag[:space] = flag[:space] + 1
170
173
  i = flag[:space]
171
174
  end
172
- hash = {:type => self.has_attribute?('type') ? self.type : self.class, :num => self.has_attribute?('num') ? self.num : 0, :pos => i}
175
+ hash = {:type => new_clazz, :num => self.has_attribute?('num') ? (self.num || 0) : 0, :pos => i}
173
176
  #If its an already existing record them get its existence hash, and then remove it from the cache.
174
177
  else
175
- hash = self.class.get_existence_hash(self.send("#{self.class.route_id}_was"))
178
+ hash = Rails.cache.read("#{superclazz}/ExistenceHash/#{old_clazz}/#{old_key}")
176
179
  hash[:type] = new_clazz
177
- Rails.cache.delete("#{superclazz}/ExistenceHash/#{old_clazz}/#{old_key}")
178
180
  end
179
181
 
182
+ #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]}")
186
+
180
187
  #If the record is not being destroyed add new route_id to existence hash
181
188
  if alive
182
189
  Rails.cache.write("#{superclazz}/ExistenceHash/#{new_clazz}/#{new_key}", hash)
183
- Rails.cache.write("#{superclazz}/ExistenceHash/#{hash[:pos]}", {:key => new_key, :type => new_clazz})
184
- #The following check is needed if for some reason someone does destroy on a none saved record.
185
- elsif !self.new_record?
190
+ Rails.cache.write("#{superclazz}/ExistenceHash/#{hash[:pos]}", {:type => new_clazz, :key => new_key})
191
+ else
186
192
  if hash[:pos] == flag[:space]
187
193
  flag[:space] = flag[:space] - 1
188
194
  else
@@ -190,7 +196,6 @@ module FlagpoleSitta
190
196
  Rails.cache.write("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}", hash[:pos])
191
197
  end
192
198
  flag[:count] = flag[:count] - 1
193
- Rails.cache.delete("#{superclazz}/ExistenceHash/#{hash[:pos]}")
194
199
  end
195
200
 
196
201
  Rails.cache.write("#{superclazz}/ExistenceHash/Flag", flag)
@@ -1,3 +1,3 @@
1
1
  module FlagpoleSitta
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.2"
3
3
  end
metadata CHANGED
@@ -1,46 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: flagpole_sitta
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 2
10
+ version: 0.9.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Andrew Rove (Rover)
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-08-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: dalli
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- description: ! "Flagpole Sitta is a gem that main purpose is to make it easier to
31
- effectively fragment cache in dynamic fashions in Rails. \nWhen ever a cache is
32
- created it is associated with any model and/or record you tell it to be from the
33
- view helper method. When that model and/or record is updated all it's associated
34
- caches are cleared. \nFlagpole also expects you to put all your database calls into
35
- Procs/Lamdbas. This makes it so that your database calls wont have to happen unless
36
- your cache hasn't been created. Thus speeding up response time and reducing database
37
- traffic."
38
- email:
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: |-
35
+ Flagpole Sitta is a gem that main purpose is to make it easier to effectively fragment cache in dynamic fashions in Rails.
36
+ When ever a cache is created it is associated with any model and/or record you tell it to be from the view helper method. When that model and/or record is updated all it's associated caches are cleared.
37
+ Flagpole also expects you to put all your database calls into Procs/Lamdbas. This makes it so that your database calls wont have to happen unless your cache hasn't been created. Thus speeding up response time and reducing database traffic.
38
+ email:
39
39
  - rovermicrover@gmail.com
40
40
  executables: []
41
+
41
42
  extensions: []
43
+
42
44
  extra_rdoc_files: []
43
- files:
45
+
46
+ files:
44
47
  - .gitignore
45
48
  - Gemfile
46
49
  - Gemfile.lock
@@ -94,26 +97,36 @@ files:
94
97
  - test/test_helper.rb
95
98
  homepage: https://github.com/rovermicrover/FlagpoleSitta
96
99
  licenses: []
100
+
97
101
  post_install_message:
98
102
  rdoc_options: []
99
- require_paths:
103
+
104
+ require_paths:
100
105
  - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
102
107
  none: false
103
- requirements:
104
- - - ! '>='
105
- - !ruby/object:Gem::Version
106
- version: '0'
107
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
116
  none: false
109
- requirements:
110
- - - ! '>='
111
- - !ruby/object:Gem::Version
112
- version: '0'
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
113
124
  requirements: []
125
+
114
126
  rubyforge_project:
115
127
  rubygems_version: 1.8.24
116
128
  signing_key:
117
129
  specification_version: 3
118
130
  summary: FlagpoleSitta is a gem for effective dynamic caching
119
131
  test_files: []
132
+