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 +4 -4
- data/README.md +10 -10
- data/h2ocube_rails_cache.gemspec +1 -1
- data/lib/active_support/cache/h2ocube_rails_cache.rb +13 -9
- data/test/cache_test.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970d3130443c25f9d9ad4b4ea743a093c855c278
|
4
|
+
data.tar.gz: 6988038c4058ffbb5e92d835b3ad193856c532cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
24
|
-
* `write key, entry, options =
|
25
|
-
* `fetch key, options =
|
26
|
-
* `delete key, options =
|
27
|
-
* `exist? key, options =
|
28
|
-
* `increment key, amount = 1, options =
|
29
|
-
* `decrement key, amount = 1, options =
|
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
|
-
* `
|
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
|
-
* `
|
41
|
-
* `
|
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
|
|
data/h2ocube_rails_cache.gemspec
CHANGED
@@ -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.
|
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
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
32
|
+
fetch_raw(key, options) do
|
33
|
+
yield
|
34
|
+
end
|
29
35
|
end
|
30
36
|
else
|
31
|
-
|
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 '
|
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 '
|
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 '
|
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 '
|
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
|
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.
|
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-
|
11
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-namespace
|