rails_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/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
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
 
@@ -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
- if blk && (RailsCacheIt.cache_it[cache_name] != (new_result = blk.call))
15
- RailsCacheIt.cache_it[cache_name] = new_result
16
- Rails.cache.delete cache_name
17
- end
18
- Rails.cache.fetch(cache_name, options) do
19
- self.to_a_without_cache_it
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
@@ -1,3 +1,3 @@
1
1
  module RailsCacheIt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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{a db cache implement based on ActiveRecord}
12
- spec.summary = %q{help you cache with ActiveRecord simpler}
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.1
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-09 00:00:00.000000000 Z
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: a db cache implement based on ActiveRecord
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: help you cache with ActiveRecord simpler
86
+ summary: ! 'Model.where(xx: xx).cache_it... it''s all ok!'
87
87
  test_files: []