model_cached 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/model_cached.rb +1 -0
- data/model_cached-0.1.1.gem +0 -0
- data/model_cached.gemspec +1 -1
- data/test/helper.rb +2 -0
- data/test/model_cached_test.rb +14 -2
- metadata +7 -6
data/lib/model_cached.rb
CHANGED
@@ -8,6 +8,7 @@ module ModelCached
|
|
8
8
|
options = {logical_delete: nil, scope: nil}.merge(column_names.extract_options!)
|
9
9
|
options[:columns] = column_names
|
10
10
|
after_save :refresh_mc_keys
|
11
|
+
after_touch :refresh_mc_keys
|
11
12
|
after_destroy :expire_mc_keys
|
12
13
|
class_eval %{ def self.mc_options; #{options}; end }
|
13
14
|
column_names.each do |column|
|
Binary file
|
data/model_cached.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'model_cached'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.2'
|
4
4
|
s.authors = ['Ary Djmal']
|
5
5
|
s.email = ['arydjmal@gmail.com']
|
6
6
|
s.summary = 'Rails gem that gives you the ability to transparently cache single active record objects using memcached.'
|
data/test/helper.rb
CHANGED
@@ -13,12 +13,14 @@ ActiveRecord::Base.establish_connection({
|
|
13
13
|
ActiveRecord::Schema.define do
|
14
14
|
create_table :accounts do |t|
|
15
15
|
t.string :name
|
16
|
+
t.timestamps
|
16
17
|
end
|
17
18
|
|
18
19
|
create_table :users do |t|
|
19
20
|
t.string :email
|
20
21
|
t.integer :account_id
|
21
22
|
t.boolean :deleted
|
23
|
+
t.timestamps
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
data/test/model_cached_test.rb
CHANGED
@@ -81,9 +81,12 @@ end
|
|
81
81
|
|
82
82
|
class ModelCachedWithScopeTest < Test::Unit::TestCase
|
83
83
|
def setup
|
84
|
+
Account.delete_all
|
84
85
|
User.delete_all
|
85
|
-
|
86
|
-
|
86
|
+
Account.send(:cache_by, :name)
|
87
|
+
User.send(:belongs_to, :account, touch: true)
|
88
|
+
User.send(:cache_by, :id, :email, scope: :account_id)
|
89
|
+
@account = Account.create!(:name => 'NaturalBits')
|
87
90
|
@ary = @account.users.create!(:email => 'Ary')
|
88
91
|
@nati = @account.users.create!(:email => 'Nati')
|
89
92
|
Rails.cache.clear
|
@@ -138,6 +141,15 @@ class ModelCachedWithScopeTest < Test::Unit::TestCase
|
|
138
141
|
assert_equal nil, Rails.cache.read("users/email/Ary/account_id:#{@account.id}")
|
139
142
|
assert_equal @ary, Rails.cache.read("users/email/new_email/account_id:#{@account.id}")
|
140
143
|
end
|
144
|
+
|
145
|
+
def test_refresh_on_parent_touch
|
146
|
+
assert_equal nil, Rails.cache.read('accounts/name/NaturalBits')
|
147
|
+
@account = Account.find_by_name('NaturalBits')
|
148
|
+
assert_equal @account.cache_key, Rails.cache.read('accounts/name/NaturalBits').cache_key
|
149
|
+
sleep 1.second
|
150
|
+
@ary.save!
|
151
|
+
assert_not_equal @account.cache_key, Rails.cache.read('accounts/name/NaturalBits').cache_key
|
152
|
+
end
|
141
153
|
end
|
142
154
|
|
143
155
|
class ModelCachedWithLogicalDeleteTest < Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70278648773480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70278648773480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70278648772620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70278648772620
|
36
36
|
description:
|
37
37
|
email:
|
38
38
|
- arydjmal@gmail.com
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- ./lib/model_cached.rb
|
44
44
|
- ./MIT-LICENSE
|
45
45
|
- ./model_cached-0.1.0.gem
|
46
|
+
- ./model_cached-0.1.1.gem
|
46
47
|
- ./model_cached.gemspec
|
47
48
|
- ./Rakefile
|
48
49
|
- ./README.rdoc
|