group_cache_key 0.1.0 → 0.2.0

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.rdoc +16 -1
  2. data/VERSION +1 -1
  3. data/lib/group_cache_key.rb +3 -1
  4. metadata +2 -2
data/README.rdoc CHANGED
@@ -1,6 +1,21 @@
1
1
  = group_cache_key
2
2
 
3
- Using this gem in an application using ActiveRecord will provide you with a 'cache_key' method on collections of models.
3
+ Using this gem in an application using ActiveRecord will provide you with a 'cache_key'
4
+ method on collections of models.
5
+
6
+ The 'cache_key' will consist of:
7
+
8
+ * the tableized name of the class of the first item
9
+ * an MD5 hash of the ids in the collection
10
+ * to_i on the max created_at date
11
+ * to_i on the max updated_at date
12
+
13
+ The 'cache_key' should look like:
14
+
15
+ 'widgets/100-81dc9bdb52d04dc20036dbd8313ed055-1256853629-1256853637'
16
+
17
+ The resulting cache_key will be different if your group is sorted differently because
18
+ the MD5 hash is created according to the order given: no sorting is done to create the hash.
4
19
 
5
20
  Built by Saturn Flyer http://www.saturnflyer.com
6
21
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,5 +1,6 @@
1
1
  require 'activerecord'
2
2
  require 'activesupport'
3
+ require 'digest/md5'
3
4
 
4
5
  ActiveRecord::Base.class_eval {
5
6
  Array.class_eval {
@@ -7,9 +8,10 @@ ActiveRecord::Base.class_eval {
7
8
  if self.empty?
8
9
  'empty'
9
10
  else
11
+ ids_hash = Digest::MD5.hexdigest(self.collect{|item| item.id }.to_s)
10
12
  update_timestamp = max {|a,b| a.updated_at <=> b.updated_at }.updated_at.to_i.to_s
11
13
  create_timestamp = max {|a,b| a.created_at <=> b.created_at }.created_at.to_i.to_s
12
- self.first.class.to_s.underscore+'/'+length.to_s+'-'+create_timestamp+'-'+update_timestamp
14
+ self.first.class.to_s.tableize+'/'+length.to_s+'-'+ids_hash+'-'+create_timestamp+'-'+update_timestamp
13
15
  end
14
16
  end
15
17
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: group_cache_key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -04:00
12
+ date: 2009-10-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency