CachedSupermodel 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/cached_supermodel.rb'
6
6
 
7
- Hoe.new('CachedSupermodel', '0.1.0') do |p|
7
+ Hoe.new('CachedSupermodel', '0.1.1') do |p|
8
8
  p.rubyforge_name = 'adocca-plugins'
9
9
  p.summary = 'A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.'
10
10
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
@@ -53,7 +53,7 @@ class ActiveRecord::Base
53
53
  attribute_values = attributes.collect do |attribute|
54
54
  self[attribute.to_sym]
55
55
  end
56
- expire_cached_namespace(self.class.name + ":#{finder}:" + attribute_values.inspect)
56
+ expire_cached_namespace("CachedSupermodel:" + self.class.name + ":#{finder}:" + attribute_values.inspect)
57
57
  end
58
58
  else
59
59
  raise "Unknown finder type #{finder}"
@@ -65,7 +65,7 @@ def self.#{finder}_get_ids(*args)
65
65
  attributes = match[2].to_s.split(/_and_/)
66
66
  normal_arguments = args[0...attributes.size]
67
67
  rest = args[attributes.size..-1]
68
- cache_value([self.name + ':#{finder}:' + normal_arguments.inspect, rest.inspect]) do
68
+ cache_value(['CachedSupermodel:' + self.name + ':#{finder}:' + normal_arguments.inspect, rest.inspect]) do
69
69
  rval = method_missing(:#{finder}, *args)
70
70
  if Array === rval
71
71
  rval.collect(&:id)
@@ -23,7 +23,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
23
23
  type_field = reflection.primary_key_name.gsub(/_id$/, "_type")
24
24
  expire_proc = Proc.new do |instance|
25
25
  if instance.send(type_field) == our_name
26
- key = "#{our_name}:#{instance.send(reflection.primary_key_name)}:#{reflection.name}"
26
+ key = "CachedSupermodel:#{our_name}:#{instance.send(reflection.primary_key_name)}:#{reflection.name}"
27
27
  expire_cached_value(key)
28
28
  end
29
29
  end
@@ -32,7 +32,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
32
32
  # Add invalidations for normal associations.
33
33
  #
34
34
  expire_proc = Proc.new do |instance|
35
- key = "#{our_name}:#{instance.send(reflection.primary_key_name)}:#{reflection.name}"
35
+ key = "CachedSupermodel:#{our_name}:#{instance.send(reflection.primary_key_name)}:#{reflection.name}"
36
36
  expire_cached_value(key)
37
37
  end
38
38
  end
@@ -60,7 +60,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
60
60
  retval = assoc.reload
61
61
  association = retval.nil? ? nil : assoc
62
62
  else
63
- key = "#{self.class.name}:#{self.id}:#{reflection.name}"
63
+ key = "CachedSupermodel:#{self.class.name}:#{self.id}:#{reflection.name}"
64
64
  expire_cached_value(key) if force_reload
65
65
  association = cache_value(key) do
66
66
  assoc = association_proxy_class.new(self.remove_associations, reflection)
@@ -164,7 +164,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
164
164
  type_field = invalidating_reflection.primary_key_name.gsub(/_id$/, '_type')
165
165
  expire_proc = Proc.new do |instance|
166
166
  if instance.send(type_field) == our_name
167
- key = "#{our_name}:#{instance.send(invalidating_reflection.primary_key_name)}:#{reflection.name}"
167
+ key = "CachedSupermodel:#{our_name}:#{instance.send(invalidating_reflection.primary_key_name)}:#{reflection.name}"
168
168
  expire_cached_value(key)
169
169
  key << ":cached_count"
170
170
  expire_cached_value(key)
@@ -175,7 +175,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
175
175
  # Non-polymorphic associations just invalidate their object regardless.
176
176
  #
177
177
  expire_proc = Proc.new do |instance|
178
- key = "#{our_name}:#{instance.send(invalidating_reflection.primary_key_name)}:#{reflection.name}"
178
+ key = "CachedSupermodel:#{our_name}:#{instance.send(invalidating_reflection.primary_key_name)}:#{reflection.name}"
179
179
  expire_cached_value(key)
180
180
  key << ":cached_count"
181
181
  expire_cached_value(key)
@@ -196,7 +196,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
196
196
  #
197
197
  write_inheritable_array("before_remove_for_#{reflection.name}".to_sym,
198
198
  [Proc.new do |owner, record|
199
- key = "#{owner.class.name}:#{owner.id}:#{reflection.name}"
199
+ key = "CachedSupermodel:#{owner.class.name}:#{owner.id}:#{reflection.name}"
200
200
  expire_cached_value(key)
201
201
  key << ":cached_count"
202
202
  expire_cached_value(key)
@@ -204,7 +204,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
204
204
 
205
205
  class_eval "
206
206
  def self.#{reflection.name}_cached_count_for(oid)
207
- key = self.name + ':' + oid.to_s + ':#{reflection.name}:cached_count'
207
+ key = 'CachedSupermodel:' + self.name + ':' + oid.to_s + ':#{reflection.name}:cached_count'
208
208
  cache_value(key) do
209
209
  self.find(oid).#{reflection.name}_cached_count
210
210
  end
@@ -215,7 +215,7 @@ end
215
215
  # The getter for the cached count of this association.
216
216
  #
217
217
  define_method("#{reflection.name}_cached_count") do |*params|
218
- key = "#{self.class.name}:#{self.id}:#{reflection.name}:cached_count"
218
+ key = "CachedSupermodel:#{self.class.name}:#{self.id}:#{reflection.name}:cached_count"
219
219
  cache_value(key) do
220
220
  association_proxy_class.new(self.remove_associations, reflection).count
221
221
  end
@@ -232,7 +232,7 @@ end
232
232
  if new_record?
233
233
  association = association_proxy_class.new(self, reflection)
234
234
  else
235
- key = "#{self.class.name}:#{self.id}:#{reflection.name}"
235
+ key = "CachedSupermodel:#{self.class.name}:#{self.id}:#{reflection.name}"
236
236
  expire_cached_value(key) if force_reload
237
237
  association = cache_value(key) do
238
238
  a = association_proxy_class.new(self.remove_associations, reflection)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: CachedSupermodel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-11-13 00:00:00 +01:00
6
+ version: 0.1.1
7
+ date: 2006-11-23 00:00:00 +01:00
8
8
  summary: A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.
9
9
  require_paths:
10
10
  - lib