h2ocube_rails_cache 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb26049cd9b2c220429a627cd0e72106c283215a
4
- data.tar.gz: a3886f5a62833fc2334bd14027c6de2f40fb5d21
3
+ metadata.gz: 970d3130443c25f9d9ad4b4ea743a093c855c278
4
+ data.tar.gz: 6988038c4058ffbb5e92d835b3ad193856c532cf
5
5
  SHA512:
6
- metadata.gz: d9dc5b840bbeae7865f2206dc0f2650717782f41ebd568b29177f132b238a58703241d0d23b9a7665f754f900cddf272212c297da8985aa499edf95f16c74341
7
- data.tar.gz: e90bd05c7877aa8a9f96c58cd567482a82ce0a5d869e080c267ed239f231c549f142eee5925f2603496ecf0a162d49f8f9206be1d9c7bd96264d48d47c1eba6c
6
+ metadata.gz: 225df978a051539130158dd667649f3484a2de61d05f9e7504129a3911005f84b38ea32d2d888cb945f1e90ae2bc803a234a2789dbca7ddf07acd25a820a88d7
7
+ data.tar.gz: 170ca11920ba240eb2f878047b61b66033c2f88564e09d6e55d73d2c68f2d3370f178c5a96c566d7cbac3069d58146937a5d65032f6758727ca821a6c9760f0a
data/README.md CHANGED
@@ -20,25 +20,25 @@ Disable default session_store in config/initializers/session_store.rb
20
20
  ## Rails.cache support methods
21
21
 
22
22
  * `keys key = '*'`
23
- * `read key, options = nil`
24
- * `write key, entry, options = nil`
25
- * `fetch key, options = nil, &block`
26
- * `delete key, options = nil`
27
- * `exist? key, options = nil`
28
- * `increment key, amount = 1, options = nil`
29
- * `decrement key, amount = 1, options = nil`
23
+ * `read key, options = {}`
24
+ * `write key, entry, options = {}`
25
+ * `fetch key, options = {}, &block`
26
+ * `delete key, options = {}`
27
+ * `exist? key, options = {}`
28
+ * `increment key, amount = 1, options = {}`
29
+ * `decrement key, amount = 1, options = {}`
30
30
  * `clear`
31
31
  * `info`
32
32
 
33
33
  ## Write Options
34
34
 
35
- * `created_at` will write timestamp with key_created_at
35
+ * `updated_at` will write timestamp with key_updated_at
36
36
 
37
37
  ## Fetch Options
38
38
 
39
39
  * `expires_in` such as 5.minutes
40
- * `if` true / false or Proc that return true / false
41
- * `created_at` will write timestamp with key_created_at
40
+ * `force` true / false or Proc that return true / false
41
+ * `updated_at` will write timestamp with key_updated_at
42
42
 
43
43
  ## Task changed
44
44
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'h2ocube_rails_cache'
7
- gem.version = '0.0.11'
7
+ gem.version = '0.0.12'
8
8
  gem.authors = ['Ben']
9
9
  gem.email = ['ben@h2ocube.com']
10
10
  gem.description = 'Just an redis cache.'
@@ -18,19 +18,23 @@ module ActiveSupport
18
18
  def fetch(key, options = {}, &block)
19
19
  key = expanded_key key
20
20
 
21
- if options.key?(:force)
22
- result = options[:force].is_a?(Proc) ? options[:force].call(key, options) : options[:force]
23
- if result
24
- fetch_raw key, options do
25
- yield
21
+ if exist?(key)
22
+ if options.key?(:force)
23
+ force = options[:force].is_a?(Proc) ? options[:force].call(key, options) : options[:force]
24
+ if force
25
+ write key, yield, options
26
+ else
27
+ fetch_raw key, options do
28
+ yield
29
+ end
26
30
  end
27
31
  else
28
- write key, yield, options
32
+ fetch_raw(key, options) do
33
+ yield
34
+ end
29
35
  end
30
36
  else
31
- fetch_raw(key, options) do
32
- yield
33
- end
37
+ write key, yield, options
34
38
  end
35
39
  end
36
40
 
data/test/cache_test.rb CHANGED
@@ -117,19 +117,19 @@ describe 'h2ocube_rails_cache' do
117
117
 
118
118
  Rails.cache.fetch 'fetch force', force: true do
119
119
  'true'
120
- end.must_equal 'content'
120
+ end.must_equal 'true'
121
121
 
122
122
  Rails.cache.fetch 'fetch force', force: -> (key, options) { true } do
123
- 'true'
124
- end.must_equal 'content'
123
+ 'true again'
124
+ end.must_equal 'true again'
125
125
 
126
126
  Rails.cache.fetch 'fetch force', force: false do
127
127
  'false'
128
- end.must_equal 'false'
128
+ end.must_equal 'true again'
129
129
 
130
130
  Rails.cache.fetch 'fetch force', force: -> (key, options) { false } do
131
131
  'false again'
132
- end.must_equal 'false again'
132
+ end.must_equal 'true again'
133
133
  end
134
134
 
135
135
  it 'fetch with updated_at' do
@@ -142,7 +142,7 @@ describe 'h2ocube_rails_cache' do
142
142
  sleep 1
143
143
 
144
144
  now = Time.now.to_i
145
- Rails.cache.fetch 'fetch updated_at', updated_at: true, force: -> (key, options) { now < Rails.cache.read("#{key}_updated_at") } do
145
+ Rails.cache.fetch 'fetch updated_at', updated_at: true, force: -> (key, options) { now > Rails.cache.read("#{key}_updated_at") } do
146
146
  'new content'
147
147
  end.must_equal 'new content'
148
148
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: h2ocube_rails_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-namespace