h2ocube_rails_cache 0.0.5 → 0.0.6
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.
- checksums.yaml +4 -4
- data/h2ocube_rails_cache.gemspec +1 -1
- data/lib/active_support/cache/h2ocube_rails_cache.rb +16 -4
- data/test/cache_test.rb +16 -1
- 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: 657f78bdaacc3a23c1818efcb2ac4c89ca56b931
|
4
|
+
data.tar.gz: 55584cf5e7d903938d0574afa7d46cb5320c8fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5553fe160a03a59bfb31515f1edf98e30842291519e7d841b977024b8b230bf6b0107f6ae42d91a58c22e3f9e91a0ae415a0720941554376643c64a14310aa1
|
7
|
+
data.tar.gz: 026a45b3d11b114da8f6824ce9f128d5a8ae4a9db101f07e74dc8889d6cf7d3a8cd8a02270c9d080cb8e38674074003b93a17a22665ef4f03556a0977e262cbb
|
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.6'
|
8
8
|
gem.authors = ['Ben']
|
9
9
|
gem.email = ['ben@h2ocube.com']
|
10
10
|
gem.description = 'Just an redis cache.'
|
@@ -11,9 +11,16 @@ module ActiveSupport
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def keys key = '*'
|
14
|
+
key = expanded_key key
|
14
15
|
@data.keys key
|
15
16
|
end
|
16
17
|
|
18
|
+
def fetch key, options = nil
|
19
|
+
key = expanded_key key
|
20
|
+
write key, yield, options if block_given? && !exist?(key)
|
21
|
+
read key, options
|
22
|
+
end
|
23
|
+
|
17
24
|
def read key, options = nil
|
18
25
|
key = expanded_key key
|
19
26
|
return nil if key.start_with?('http')
|
@@ -25,6 +32,7 @@ module ActiveSupport
|
|
25
32
|
end
|
26
33
|
|
27
34
|
def read_raw key, options = nil
|
35
|
+
key = expanded_key key
|
28
36
|
@data.get key
|
29
37
|
end
|
30
38
|
|
@@ -36,13 +44,15 @@ module ActiveSupport
|
|
36
44
|
true
|
37
45
|
end
|
38
46
|
|
39
|
-
def delete
|
40
|
-
|
47
|
+
def delete key, options = nil
|
48
|
+
key = expanded_key key
|
49
|
+
@data.keys(key).each{ |k| @data.del k }
|
41
50
|
true
|
42
51
|
end
|
43
52
|
|
44
|
-
def exist?
|
45
|
-
|
53
|
+
def exist? key, options = nil
|
54
|
+
key = expanded_key key
|
55
|
+
@data.exists key
|
46
56
|
end
|
47
57
|
|
48
58
|
def clear
|
@@ -55,6 +65,7 @@ module ActiveSupport
|
|
55
65
|
end
|
56
66
|
|
57
67
|
def increment key, amount = 1, options = nil
|
68
|
+
key = expanded_key key
|
58
69
|
if amount == 1
|
59
70
|
@data.incr key
|
60
71
|
else
|
@@ -63,6 +74,7 @@ module ActiveSupport
|
|
63
74
|
end
|
64
75
|
|
65
76
|
def decrement key, amount = 1, options = nil
|
77
|
+
key = expanded_key key
|
66
78
|
if amount == 1
|
67
79
|
@data.decr key
|
68
80
|
else
|
data/test/cache_test.rb
CHANGED
@@ -44,7 +44,7 @@ describe 'h2ocube_rails_cache' do
|
|
44
44
|
Rails.cache.delete 'expire'
|
45
45
|
Rails.cache.write 'expire', 1, expires_in: 1
|
46
46
|
Rails.cache.exist?('expire').must_be_same_as true
|
47
|
-
sleep
|
47
|
+
sleep 2
|
48
48
|
Rails.cache.exist?('expire').must_be_same_as false
|
49
49
|
end
|
50
50
|
|
@@ -83,6 +83,21 @@ describe 'h2ocube_rails_cache' do
|
|
83
83
|
Rails.cache.decrement 'number', 2
|
84
84
|
Rails.cache.read('number').must_equal 1
|
85
85
|
end
|
86
|
+
|
87
|
+
it 'fetch' do
|
88
|
+
Rails.cache.fetch 'fetch' do
|
89
|
+
'fetch content'
|
90
|
+
end.must_equal 'fetch content'
|
91
|
+
|
92
|
+
Rails.cache.read('fetch').must_equal 'fetch content'
|
93
|
+
|
94
|
+
Rails.cache.fetch 'fetch expire', expires_in: 1.seconds do
|
95
|
+
'fetch content'
|
96
|
+
end.must_equal 'fetch content'
|
97
|
+
Rails.cache.read('fetch expire').must_equal 'fetch content'
|
98
|
+
sleep 2
|
99
|
+
Rails.cache.exist?('fetch expire').must_be_same_as false
|
100
|
+
end
|
86
101
|
end
|
87
102
|
|
88
103
|
describe ApplicationController do
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-namespace
|