CachedSupermodel 0.1.2.1 → 0.1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.txt +16 -0
  2. data/Rakefile +1 -1
  3. data/lib/cs_associations.rb +16 -16
  4. metadata +5 -4
data/README.txt CHANGED
@@ -14,6 +14,22 @@ their code, but added so much that it merited its own plugin.
14
14
  Apologies for not doing proper contributions to their project instead of building our own, but
15
15
  we are limited by commercial requirements rather than open source idealism.
16
16
 
17
+ === Cached Super Model: a short introduction.
18
+
19
+ This works a lot like <tt>acts_as_cached_model</tt>, but with a few subtle differences.
20
+
21
+ CachedSuperModel caches more aggressively than <tt>cached_model</tt>.
22
+
23
+ When using conditions or joins, it will not cache, so you need to develop with the caching in mind.
24
+
25
+ The good old <tt>cached_model</tt> only caches on find_by_id {:limit => 1} but CachedSuperModel caches all associations.
26
+
27
+ So you get to declare <tt>cached_finders</tt>. Example:
28
+
29
+ cached_finder :find_all_by_user_id_and_password_and_hat
30
+
31
+ Then, when run, that query will be cached.
32
+
17
33
  == FEATURES/PROBLEMS:
18
34
 
19
35
  * Through associations are not invalidated _at_all_ in the end association right now. Ex:
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.2.1') do |p|
7
+ Hoe.new('CachedSupermodel', '0.1.2.2') do |p|
8
8
  p.summary = 'A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.'
9
9
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
10
10
  p.author = 'adocca Entertainment AB'
@@ -35,10 +35,10 @@ ActiveRecord::Associations::ClassMethods.class_eval do
35
35
  key = "CachedSupermodel:#{our_name}:#{instance.send(reflection.primary_key_name)}:#{reflection.name}"
36
36
  expire_cached_value(key)
37
37
  end
38
- end
39
-
40
- before_destroy expire_proc
41
- before_save expire_proc
38
+ end
39
+
40
+ after_destroy expire_proc
41
+ after_save expire_proc
42
42
 
43
43
  var_name = "@@association_invalidations"
44
44
  class_variable_set(var_name, []) unless class_variables.include?(var_name)
@@ -53,7 +53,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
53
53
  define_method(reflection.name) do |*params|
54
54
  force_reload = params.first unless params.empty?
55
55
  association = instance_variable_get("@#{reflection.name}")
56
-
56
+
57
57
  if association.nil? || force_reload
58
58
  if new_record?
59
59
  assoc = association_proxy_class.new(self, reflection)
@@ -77,11 +77,11 @@ ActiveRecord::Associations::ClassMethods.class_eval do
77
77
  #
78
78
  # If this wasnt has_one, do the normal stuff.
79
79
  #
80
-
80
+
81
81
  define_method(reflection.name) do |*params|
82
82
  force_reload = params.first unless params.empty?
83
83
  association = instance_variable_get("@#{reflection.name}")
84
-
84
+
85
85
  if association.nil? || force_reload
86
86
  association = association_proxy_class.new(self, reflection)
87
87
  retval = association.reload
@@ -94,9 +94,9 @@ ActiveRecord::Associations::ClassMethods.class_eval do
94
94
  end
95
95
  association
96
96
  end
97
-
97
+
98
98
  end
99
-
99
+
100
100
  #
101
101
  # Here ends our customization, the rest is just copy and paste except for a few invalidations.
102
102
  #
@@ -110,7 +110,7 @@ ActiveRecord::Associations::ClassMethods.class_eval do
110
110
  invalidation.call(me)
111
111
  end if class_variables.include?("@@association_invalidations")
112
112
  end
113
-
113
+
114
114
  association = instance_variable_get("@#{reflection.name}")
115
115
  if association.nil?
116
116
  association = association_proxy_class.new(self, reflection)
@@ -181,8 +181,8 @@ ActiveRecord::Associations::ClassMethods.class_eval do
181
181
  expire_cached_value(key)
182
182
  end
183
183
  end
184
- before_destroy expire_proc
185
- before_save expire_proc
184
+ after_destroy expire_proc
185
+ after_save expire_proc
186
186
 
187
187
  var_name = "@@association_invalidations"
188
188
  class_variable_set(var_name, []) unless class_variables.include?(var_name)
@@ -194,14 +194,14 @@ ActiveRecord::Associations::ClassMethods.class_eval do
194
194
  #
195
195
  # We also have to add before_remove callbacks to the owner class
196
196
  #
197
- write_inheritable_array("before_remove_for_#{reflection.name}".to_sym,
197
+ write_inheritable_array("before_remove_for_#{reflection.name}".to_sym,
198
198
  [Proc.new do |owner, record|
199
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)
203
203
  end])
204
-
204
+
205
205
  class_eval "
206
206
  def self.#{reflection.name}_cached_count_for(oid)
207
207
  key = 'CachedSupermodel:' + self.name + ':' + oid.to_s + ':#{reflection.name}:cached_count'
@@ -210,7 +210,7 @@ def self.#{reflection.name}_cached_count_for(oid)
210
210
  end
211
211
  end
212
212
  "
213
-
213
+
214
214
  #
215
215
  # The getter for the cached count of this association.
216
216
  #
@@ -227,7 +227,7 @@ end
227
227
  define_method(reflection.name) do |*params|
228
228
  force_reload = params.first unless params.empty?
229
229
  association = instance_variable_get("@#{reflection.name}")
230
-
230
+
231
231
  if !association.respond_to?(:loaded?) || force_reload
232
232
  if new_record?
233
233
  association = association_proxy_class.new(self, reflection)
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: CachedSupermodel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2.1
7
- date: 2006-12-22 00:00:00 +01:00
6
+ version: 0.1.2.2
7
+ date: 2007-01-16 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
11
11
  email: ryand-ruby@zenspider.com
12
12
  homepage: " by Adocca AB"
13
13
  rubyforge_project: adocca-plugins
14
- description: "Based on cached_model by <a href=\"http://dev.robotcoop.com/\">robotcoop</a>. We started out with their code, but added so much that it merited its own plugin. Apologies for not doing proper contributions to their project instead of building our own, but we are limited by commercial requirements rather than open source idealism. == FEATURES/PROBLEMS: * Through associations are not invalidated _at_all_ in the end association right now. Ex: * User has_many :taggings * User has_many :tags, :through => :taggings, :source => :tag * If you now remove tags without removing taggings the user will still have those tags in the User#tags collection. == SYNOPSYS:"
14
+ description: "Based on cached_model by <a href=\"http://dev.robotcoop.com/\">robotcoop</a>. We started out with their code, but added so much that it merited its own plugin. Apologies for not doing proper contributions to their project instead of building our own, but we are limited by commercial requirements rather than open source idealism. === Cached Super Model: a short introduction. This works a lot like <tt>acts_as_cached_model</tt>, but with a few subtle differences."
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - adocca Entertainment AB
30
31
  files: