cache_it 0.0.1 → 0.0.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/README +42 -6
- data/cache_it.gemspec +4 -0
- data/lib/cache_it/version.rb +1 -1
- data/lib/cache_it.rb +1 -0
- data/spec/cache_it_spec.rb +22 -1
- metadata +56 -5
data/README
CHANGED
@@ -1,23 +1,59 @@
|
|
1
1
|
cache_it
|
2
2
|
========
|
3
3
|
|
4
|
-
Cache for ActiveRecord objects, backed by ActiveSupport::CacheStore of your choice.
|
5
|
-
not yet ported to Rails 3 so I rolled my own.
|
4
|
+
Cache for ActiveRecord objects, backed by ActiveSupport::CacheStore of your choice.
|
6
5
|
|
7
6
|
|
8
7
|
Example
|
9
8
|
=======
|
10
9
|
|
10
|
+
create table users (
|
11
|
+
`id` int(11) not null increment,
|
12
|
+
`first` varchar(255),
|
13
|
+
`last` varchar(255),
|
14
|
+
`email` varchar(255),
|
15
|
+
`age` int(11),
|
16
|
+
`points` int(11),
|
17
|
+
primary key (`id`),
|
18
|
+
unique key `index_users_on_email` (`email`),
|
19
|
+
unique key `index_users_on_last_first` (`last`, `first`)
|
20
|
+
);
|
21
|
+
|
11
22
|
class User < ActiveRecord::Base
|
12
23
|
cache_it do |c|
|
13
|
-
c.index :
|
24
|
+
c.index :last, :first
|
14
25
|
c.index :email
|
26
|
+
c.counters :points
|
15
27
|
end
|
16
28
|
end
|
17
29
|
|
18
|
-
user = User.
|
19
|
-
user
|
30
|
+
user = User.cache_it.find :first => "Joe", :last => "Schmoe"
|
31
|
+
user.email = "joe@example.com"
|
32
|
+
user.points = 5
|
33
|
+
user.age = 29
|
34
|
+
user.save
|
20
35
|
user.age = 30
|
21
|
-
user.
|
36
|
+
user.cache_it.write
|
37
|
+
|
38
|
+
User.cache_it.read(:email => "joe@example.com").first.age
|
39
|
+
=> 30
|
40
|
+
User.where(:email => "joe@example.com").first.age
|
41
|
+
=> 29
|
42
|
+
user.save
|
43
|
+
=> true
|
44
|
+
User.where(:email => "joe@example.com").first.age
|
45
|
+
=> 30
|
46
|
+
|
47
|
+
user.cache_it.increment :points
|
48
|
+
=> 6
|
49
|
+
User.cache_it.read(:first => "Joe", :last => "Schmoe").points
|
50
|
+
=> 6
|
51
|
+
User.where(:first => "Joe", :last => "Schmoe").first.points
|
52
|
+
=> 5
|
53
|
+
user.save
|
54
|
+
=> true
|
55
|
+
User.where(:first => "Joe", :last => "Schmoe").first.points
|
56
|
+
=> 6
|
57
|
+
|
22
58
|
|
23
59
|
Copyright (c) 2011 Rodrigo Vanegas, released under the MIT license
|
data/cache_it.gemspec
CHANGED
@@ -13,6 +13,10 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Integrates ActiveRecord with cache stores provided by Rails.cache, incluing memcached}
|
14
14
|
|
15
15
|
s.rubyforge_project = "cache_it"
|
16
|
+
s.add_dependency 'activerecord'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'ruby-debug19'
|
19
|
+
s.add_development_dependency 'sqlite3'
|
16
20
|
|
17
21
|
s.files = `git ls-files`.split("\n")
|
18
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/cache_it/version.rb
CHANGED
data/lib/cache_it.rb
CHANGED
@@ -162,6 +162,7 @@ module CacheIt
|
|
162
162
|
obj = @base.new
|
163
163
|
obj.send :attributes=, attributes, false
|
164
164
|
obj.instance_variable_set("@new_record", false) if obj.id
|
165
|
+
obj.instance_variable_set("@changed_attributes", {}) if obj.id
|
165
166
|
obj.cache_it.init_counters unless options[:skip_counters]
|
166
167
|
end
|
167
168
|
return obj
|
data/spec/cache_it_spec.rb
CHANGED
@@ -80,6 +80,7 @@ silence_stream(STDOUT) do
|
|
80
80
|
create_table :users do |t|
|
81
81
|
t.string :code
|
82
82
|
t.string :name
|
83
|
+
t.boolean :flag, :default => false
|
83
84
|
t.integer :points, :default => 0
|
84
85
|
end
|
85
86
|
end
|
@@ -165,6 +166,26 @@ describe CacheIt do
|
|
165
166
|
it "doesn't accept unknown index" do
|
166
167
|
expect { User.cache_it.read(:points => 10) }.to raise_error(/index not available/)
|
167
168
|
end
|
169
|
+
|
170
|
+
it "saves boolean correctly on repetition" do
|
171
|
+
User.all[0].flag.should == false
|
172
|
+
u = User.cache_it.find :name => "joe"
|
173
|
+
u.flag = true
|
174
|
+
u.save
|
175
|
+
User.all[0].flag.should == true
|
176
|
+
u = User.cache_it.find :name => "joe"
|
177
|
+
u.flag = false
|
178
|
+
u.save
|
179
|
+
User.all[0].flag.should == false
|
180
|
+
u = User.cache_it.find :name => "joe"
|
181
|
+
u.flag = true
|
182
|
+
u.save
|
183
|
+
User.all[0].flag.should == true
|
184
|
+
u = User.cache_it.find :name => "joe"
|
185
|
+
u.flag = false
|
186
|
+
u.save
|
187
|
+
User.all[0].flag.should == false
|
188
|
+
end
|
168
189
|
end
|
169
190
|
|
170
191
|
context "config" do
|
@@ -226,7 +247,7 @@ describe CacheIt do
|
|
226
247
|
|
227
248
|
it "cannot config twice" do
|
228
249
|
expect {@users_class.cache_it :name}.to_not raise_error
|
229
|
-
expect {@users_class.cache_it :
|
250
|
+
expect {@users_class.cache_it :name}.to raise_error
|
230
251
|
end
|
231
252
|
end
|
232
253
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rodrigo Vanegas
|
@@ -14,10 +14,61 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-05-01 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activerecord
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-debug19
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: sqlite3
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id004
|
21
72
|
description: Integrates ActiveRecord with cache stores provided by Rails.cache, incluing memcached
|
22
73
|
email:
|
23
74
|
- rvanegas@gmail.com
|