rails_cache_it 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +6 -2
- data/lib/rails_cache_it.rb +0 -5
- data/lib/rails_cache_it/relation_extension.rb +7 -6
- data/lib/rails_cache_it/version.rb +1 -1
- data/rails_cache_it.gemspec +2 -2
- metadata +4 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RailsCacheIt
|
2
2
|
|
3
|
-
Help you cache with ActiveRecord.
|
3
|
+
Help you easy to cache with ActiveRecord.
|
4
4
|
|
5
5
|
Only support Rails program.
|
6
6
|
|
@@ -28,6 +28,10 @@ Only work on Relation now(it means you can't use it with #first #last etc..).
|
|
28
28
|
|
29
29
|
###expires
|
30
30
|
|
31
|
+
`User.limit(50).cache_it expires_in: 5.minutes`
|
32
|
+
|
33
|
+
or use block
|
34
|
+
|
31
35
|
`User.limit(50).cache_it{ User.count}`
|
32
36
|
|
33
37
|
when block.call != pre_block.call
|
@@ -39,7 +43,7 @@ view [AvtiveSupport::Cache::Store#fetch](http://api.rubyonrails.org/classes/Acti
|
|
39
43
|
|
40
44
|
###set default options
|
41
45
|
|
42
|
-
`RailsCacheIt.default_options.merge(options)`
|
46
|
+
`RailsCacheIt.default_options.merge!(options)`
|
43
47
|
|
44
48
|
## Contributing
|
45
49
|
|
data/lib/rails_cache_it.rb
CHANGED
@@ -4,14 +4,9 @@ require "rails_cache_it/relation_extension"
|
|
4
4
|
module RailsCacheIt
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
@_cache_it = {}
|
8
7
|
@_default_options = {}
|
9
8
|
|
10
9
|
class << self
|
11
|
-
def cache_it
|
12
|
-
@_cache_it
|
13
|
-
end
|
14
|
-
|
15
10
|
def default_options
|
16
11
|
@_default_options
|
17
12
|
end
|
@@ -11,13 +11,14 @@ module RailsCacheIt
|
|
11
11
|
if options
|
12
12
|
cache_name = to_sql
|
13
13
|
blk = options.delete :blk
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
blk_val = blk && blk.call
|
15
|
+
result, pre_val = Rails.cache.fetch(cache_name, options)
|
16
|
+
if result.nil? || (blk_val != pre_val)
|
17
|
+
result, _ = Rails.cache.fetch cache_name, options.merge(force: true) do
|
18
|
+
[self.to_a_without_cache_it, blk_val]
|
19
|
+
end
|
20
20
|
end
|
21
|
+
result
|
21
22
|
else
|
22
23
|
self.to_a_without_cache_it
|
23
24
|
end
|
data/rails_cache_it.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = RailsCacheIt::VERSION
|
9
9
|
spec.authors = ["jjy"]
|
10
10
|
spec.email = ["jjyruby@gmail.com"]
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.description = %q{lightweight Rails AR cache implement, very simple and easy to use }
|
12
|
+
spec.summary = %q{Model.where(xx: xx).cache_it... it's all ok!}
|
13
13
|
spec.homepage = "http://github.com/jjyr/rails_cache_it"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_cache_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description:
|
46
|
+
description: ! 'lightweight Rails AR cache implement, very simple and easy to use '
|
47
47
|
email:
|
48
48
|
- jjyruby@gmail.com
|
49
49
|
executables: []
|
@@ -83,5 +83,5 @@ rubyforge_project:
|
|
83
83
|
rubygems_version: 1.8.25
|
84
84
|
signing_key:
|
85
85
|
specification_version: 3
|
86
|
-
summary:
|
86
|
+
summary: ! 'Model.where(xx: xx).cache_it... it''s all ok!'
|
87
87
|
test_files: []
|