double_write_cache_stores 0.0.4 → 0.1.0

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: 8d14a5f53f7caef579a423332dffc1a8973abfe1
4
- data.tar.gz: 5202dc0ccb089fe2a0dde67d60b18d2e1a527128
3
+ metadata.gz: dcd53dd7056f314c57ea44c94d975750a86778cd
4
+ data.tar.gz: 0de0d1f3c473b22c5d13248b9870e9cc9acea696
5
5
  SHA512:
6
- metadata.gz: b35d929dfac751e60978469507519524f0848d26fc9cf3f5dc59b0f4edc5ca28de4c02be98947d304f4ebedc80f2d621d3801ef8e0706da5cce3bf8f7ae90b14
7
- data.tar.gz: 9803d72741ebff1ae00e9b347ef52d9ab96f60c70ce599e52b2bdeca83bbe182235fa519423d3c284b30d2e601d35c0afd1003571b8da10aa76ccb4c0395cdd2
6
+ metadata.gz: 24167f49575886bb2cbef672856da4edc1ecc607df17e27d6f412e2bc3906d92f0d6965504a647e25810d578ded66fe41a7552b12e7b302e18b448418dce356f
7
+ data.tar.gz: b217321524de1014d0cbdd65d52e1058f4e1e0704b8b30658d2c58613d8798ca1b4535c0c73842d7f62a53cadf21322d43c9eef6f14b90b95ebdaf0673cb41ca
data/README.md CHANGED
@@ -2,16 +2,10 @@
2
2
 
3
3
  pre-warning(double write to cach store and other cache store) cache store wrapper. will switch cache store.
4
4
 
5
- ## Convertible interface, get/set by cache store
5
+ ## Support
6
6
 
7
- - Padrino::Cache(moneta)
8
7
  - ActiveSupport::Cache::DalliStore(Dalli)
9
- - Padrino::Cache::Store::Memcache
10
-
11
- ## Support backend cache store
12
-
13
- - ActiveSupport::Cache::DalliStore(Dalli)
14
- - Padrino::Cache::Store::Memcache
8
+ - Padrino::Cache(v0.12.x)
15
9
 
16
10
  ## Installation
17
11
 
@@ -24,6 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "activesupport", "= 3.2.15"
25
25
  spec.add_development_dependency "dalli", "= 2.6.4"
26
26
  spec.add_development_dependency "pry"
27
- spec.add_development_dependency "padrino", "0.10.7"
28
- spec.add_development_dependency "tilt", "1.3.7"
27
+ spec.add_development_dependency "padrino", "0.12.2"
29
28
  end
@@ -40,7 +40,9 @@ class DoubleWriteCacheStores::Client
40
40
 
41
41
  def touch(key)
42
42
  result = false
43
- read_and_write_backend = @read_and_write_store.instance_variable_get('@backend') || @read_and_write_store.instance_variable_get('@data')
43
+
44
+ read_and_write_backend = get_backend @read_and_write_store
45
+
44
46
  if read_and_write_backend && read_and_write_backend.respond_to?(:touch)
45
47
  result = read_and_write_backend.touch key
46
48
  write_only_store_touch key
@@ -49,22 +51,34 @@ class DoubleWriteCacheStores::Client
49
51
  end
50
52
 
51
53
  def flush
52
- if flush_cache_store || flush_cache_store(:clear)
54
+ if flush_cache_store || flush_cache_store(:flush)
53
55
  true
54
56
  else
55
57
  false
56
58
  end
57
59
  end
58
60
 
61
+ alias :clear :flush
62
+
59
63
  private
60
64
 
65
+ def get_backend cache_store
66
+ if cache_store.is_a? Padrino::Cache::LegacyStore
67
+ cache_store.instance_variable_get('@adapter').instance_variable_get('@adapter').instance_variable_get('@backend')
68
+ else
69
+ cache_store.instance_variable_get '@backend'
70
+ end
71
+ end
72
+
61
73
  def write_cache_store(key, value, options = nil)
62
74
  set_or_write_method_call @read_and_write_store, key, value, options
63
75
  set_or_write_method_call @write_only_store, key, value, options if @write_only_store
64
76
  end
65
77
 
66
78
  def set_or_write_method_call cache_store, key, value, options
67
- if cache_store.respond_to? :set
79
+ if cache_store.respond_to? :[]=
80
+ cache_store[key] = value
81
+ elsif cache_store.respond_to? :set
68
82
  cache_store.set key, value, options
69
83
  elsif cache_store.respond_to? :write
70
84
  cache_store.write key, value, options
@@ -72,14 +86,16 @@ class DoubleWriteCacheStores::Client
72
86
  end
73
87
 
74
88
  def get_or_read_method_call key
75
- if @read_and_write_store.respond_to? :get
89
+ if @read_and_write_store.respond_to? :[]
90
+ @read_and_write_store[key]
91
+ elsif @read_and_write_store.respond_to? :get
76
92
  @read_and_write_store.get key
77
93
  elsif @read_and_write_store.respond_to? :read
78
94
  @read_and_write_store.read key
79
95
  end
80
96
  end
81
97
 
82
- def flush_cache_store(method = :flush)
98
+ def flush_cache_store(method = :clear)
83
99
  if @read_and_write_store.respond_to? method
84
100
  if @write_only_store && @write_only_store.respond_to?(method)
85
101
  @write_only_store.send method
@@ -92,8 +108,7 @@ class DoubleWriteCacheStores::Client
92
108
 
93
109
  def write_only_store_touch(key)
94
110
  if @write_only_store
95
- write_only_backend = @write_only_store.instance_variable_get('@backend') || @write_only_store.instance_variable_get('@data')
96
- if write_only_backend
111
+ if write_only_backend = get_backend(@write_only_store)
97
112
  write_only_backend.touch key if write_only_backend.respond_to?(:touch)
98
113
  end
99
114
  end
@@ -1,3 +1,3 @@
1
1
  module DoubleWriteCacheStores
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -29,10 +29,13 @@ describe DoubleWriteCacheStores::Client do
29
29
  end
30
30
  end
31
31
 
32
- describe 'set #[]=(key, value) and get #[](key)' do
33
- it 'set value and get value' do
32
+ describe '#[]=' do
33
+ before do
34
34
  copy_cache_store['key'] = 'example-value'
35
- expect(copy_cache_store['key']).to eq 'example-value'
35
+ end
36
+ it 'set value to multi store' do
37
+ expect(read_and_write_store.read 'key').to eq 'example-value'
38
+ expect(write_only_store.read 'key').to eq 'example-value'
36
39
  end
37
40
  end
38
41
 
@@ -56,10 +59,10 @@ describe DoubleWriteCacheStores::Client do
56
59
  { :namespace => "app_v1", :compress => true }
57
60
  end
58
61
  let :support_touch_read_and_write_store do
59
- Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('localhost:11211', options))
62
+ Padrino::Cache.new(:Memcached, :backend => ::Dalli::Client.new('localhost:11211', options))
60
63
  end
61
64
  let :support_touch_write_only_store do
62
- Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('localhost:21211', options))
65
+ Padrino::Cache.new(:Memcached, :backend => ::Dalli::Client.new('localhost:21211', options))
63
66
  end
64
67
  let :support_touch_copy_cache_store do
65
68
  DoubleWriteCacheStores::Client.new support_touch_read_and_write_store, support_touch_write_only_store
@@ -67,26 +70,30 @@ describe DoubleWriteCacheStores::Client do
67
70
  before do
68
71
  support_touch_copy_cache_store.set 'touch-key', 'touch-value', :expires_in => 1.day
69
72
  end
70
-
71
- context 'Dalli::Client' do
72
- it 'example' do
73
- expect(support_touch_copy_cache_store.touch 'touch-key').to be true
74
- expect(support_touch_copy_cache_store.touch 'non-set-key').to be nil
75
- end
73
+ it 'example' do
74
+ expect(support_touch_copy_cache_store.touch 'touch-key').to be_true
75
+ expect(support_touch_copy_cache_store.touch 'non-set-key').to be_nil
76
76
  end
77
-
78
- context 'ActiveSupport::Cache::DalliStore' do
79
- let :double_write_dalli_store do
80
- DoubleWriteCacheStores::Client.new ActiveSupport::Cache::DalliStore.new('localhost:11211', options), ActiveSupport::Cache::DalliStore.new('localhost:21211', options)
77
+ context 'when touch non support backend' do
78
+ before do
79
+ copy_cache_store.write 'unsupport-touch-key', 'touch-value', :expires_in => 1.day
81
80
  end
81
+ it 'not doing touch' do
82
+ expect(copy_cache_store.touch 'unsupport-touch-key').to be_false
83
+ end
84
+ end
85
+ end
82
86
 
87
+ describe '#[]' do
88
+ context 'when standard case' do
83
89
  before do
84
- double_write_dalli_store.set 'touch-key', 'touch-valule', :expires_in => 1.day
90
+ copy_cache_store.write 'key', 'example-read-value', :expires_in => 1.day
85
91
  end
86
-
87
- it 'example' do
88
- expect(double_write_dalli_store.touch 'touch-key').to be true
89
- expect(double_write_dalli_store.touch 'non-set-key').to be nil
92
+ it 'get read key value from multi store' do
93
+ expect(copy_cache_store['key']).to eq 'example-read-value'
94
+ end
95
+ it 'not get no set key-value' do
96
+ expect(copy_cache_store['not-set-key']).to be_nil
90
97
  end
91
98
  end
92
99
  end
@@ -132,10 +139,10 @@ describe DoubleWriteCacheStores::Client do
132
139
  { :namespace => "app_v1", :compress => true }
133
140
  end
134
141
  let :support_flash_read_and_write_store do
135
- Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('localhost:11211', options))
142
+ Padrino::Cache.new(:Memcached, :backend => ::Dalli::Client.new('localhost:11211', options))
136
143
  end
137
144
  let :support_flash_write_only_store do
138
- Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('localhost:21211', options))
145
+ Padrino::Cache.new(:Memcached, :backend => ::Dalli::Client.new('localhost:21211', options))
139
146
  end
140
147
  let :support_flash_copy_cache_store do
141
148
  DoubleWriteCacheStores::Client.new support_flash_read_and_write_store, support_flash_write_only_store
@@ -145,10 +152,51 @@ describe DoubleWriteCacheStores::Client do
145
152
  end
146
153
  it 'example' do
147
154
  expect(support_flash_copy_cache_store.get 'will-flush-key').to eq 'will-flush-value'
148
- expect(support_flash_copy_cache_store.flush).to be true
155
+ expect(support_flash_copy_cache_store.flush).to be_true
149
156
  expect(support_flash_copy_cache_store.get 'will-flush-key').to be_nil
150
157
  end
151
158
  end
152
159
  end
153
160
 
161
+ describe '#clear' do
162
+ before do
163
+ copy_cache_store.write 'will-flush-key', 'will-flush-value', :expires_in => 1.day
164
+ end
165
+ it 'alias #flush' do
166
+ expect(copy_cache_store.clear).to eq true
167
+ expect(copy_cache_store.read 'will-flush-key').to be_nil
168
+ end
169
+ end
170
+
171
+ describe 'check any cache_store' do
172
+ let :options do
173
+ { :namespace => "app_v1", :compress => true }
174
+ end
175
+
176
+ it 'ActiveSupport::Cache::DalliStore x ActiveSupport::Cache::DalliStore' do
177
+ any_cach_store_checks ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:11211'), ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:21211')
178
+ end
179
+
180
+ it 'Padrino::Cache x Padrino::Cache' do
181
+ write_and_read_memcached = ::Dalli::Client.new 'localhost:11211', options
182
+ read_only_memcached = ::Dalli::Client.new 'localhost:21211', options
183
+ any_cach_store_checks Padrino::Cache.new(:Memcached, :backend => write_and_read_memcached), Padrino::Cache.new(:Memcached, :backend => read_only_memcached)
184
+ end
185
+
186
+ def any_cach_store_checks read_and_write_store, write_only_store
187
+ double_write_cache_store = DoubleWriteCacheStores::Client.new read_and_write_store, write_only_store
188
+ double_write_cache_store['aaa'] = 'aaa-value'
189
+ double_write_cache_store.set 'bbb', 'bbb-value'
190
+ double_write_cache_store.write 'ccc', 'ccc-value'
191
+
192
+ expect(double_write_cache_store['aaa']).to eq 'aaa-value'
193
+ expect(double_write_cache_store.get 'bbb').to eq 'bbb-value'
194
+ expect(double_write_cache_store.read 'ccc').to eq 'ccc-value'
195
+
196
+ expect(double_write_cache_store['zzz']).to eq nil
197
+ expect(double_write_cache_store.get 'zzz').to eq nil
198
+ expect(double_write_cache_store.read 'zzz').to eq nil
199
+ end
200
+ end
201
+
154
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double_write_cache_stores
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hirocaster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,28 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.10.7
103
+ version: 0.12.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.10.7
111
- - !ruby/object:Gem::Dependency
112
- name: tilt
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '='
116
- - !ruby/object:Gem::Version
117
- version: 1.3.7
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '='
123
- - !ruby/object:Gem::Version
124
- version: 1.3.7
110
+ version: 0.12.2
125
111
  description: ' pre-warning(double write to cach store and other cache store) cache
126
112
  store wrapper. will switch cache store. '
127
113
  email: