cachy 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cachy.gemspec +6 -2
- data/lib/cachy/memcache_timeout_protection.rb +8 -3
- data/spec/cachy/memcache_timeout_protection_spec.rb +50 -0
- data/spec/cachy/memcached_wrapper_spec.rb +2 -28
- data/spec/mem_cache.rb +35 -0
- metadata +7 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/cachy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cachy}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-18}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.files = [
|
15
15
|
"Rakefile",
|
@@ -22,10 +22,12 @@ Gem::Specification.new do |s|
|
|
22
22
|
"lib/cachy/moneta_wrapper.rb",
|
23
23
|
"lib/cachy/redis_wrapper.rb",
|
24
24
|
"lib/cachy/wrapper.rb",
|
25
|
+
"spec/cachy/memcache_timeout_protection_spec.rb",
|
25
26
|
"spec/cachy/memcached_wrapper_spec.rb",
|
26
27
|
"spec/cachy/moneta_wrapper_spec.rb",
|
27
28
|
"spec/cachy/redis_wrapper_spec.rb",
|
28
29
|
"spec/cachy_spec.rb",
|
30
|
+
"spec/mem_cache.rb",
|
29
31
|
"spec/spec_helper.rb",
|
30
32
|
"spec/test_cache.rb"
|
31
33
|
]
|
@@ -37,7 +39,9 @@ Gem::Specification.new do |s|
|
|
37
39
|
s.test_files = [
|
38
40
|
"spec/cachy/memcached_wrapper_spec.rb",
|
39
41
|
"spec/cachy/moneta_wrapper_spec.rb",
|
42
|
+
"spec/cachy/memcache_timeout_protection_spec.rb",
|
40
43
|
"spec/cachy/redis_wrapper_spec.rb",
|
44
|
+
"spec/mem_cache.rb",
|
41
45
|
"spec/cachy_spec.rb",
|
42
46
|
"spec/test_cache.rb",
|
43
47
|
"spec/spec_helper.rb"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# do not let MemCache timeouts kill your app,
|
2
2
|
# mark as error and return read_error_callback (e.g. nil -> cache miss)
|
3
|
-
|
3
|
+
MemCache # class should exist at this point
|
4
4
|
|
5
5
|
class MemCache
|
6
6
|
# Add your callback to stop timeouts from raising
|
@@ -11,7 +11,10 @@ class MemCache
|
|
11
11
|
# nil
|
12
12
|
# }
|
13
13
|
|
14
|
-
|
14
|
+
class << self
|
15
|
+
attr_accessor :read_error_callback
|
16
|
+
end
|
17
|
+
attr_accessor :read_error_occurred
|
15
18
|
|
16
19
|
def cache_get_with_timeout_protection(*args)
|
17
20
|
begin
|
@@ -26,5 +29,7 @@ class MemCache
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
29
|
-
|
32
|
+
|
33
|
+
alias_method :cache_get_without_timeout_protection, :cache_get
|
34
|
+
alias_method :cache_get, :cache_get_with_timeout_protection
|
30
35
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
require 'spec/mem_cache'
|
3
|
+
require 'cachy/memcache_timeout_protection'
|
4
|
+
|
5
|
+
describe "MemCache timeout protection" do
|
6
|
+
before do
|
7
|
+
MemCache.read_error_callback = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:cache){ MemCache.new }
|
11
|
+
|
12
|
+
def simulate_timeout
|
13
|
+
cache.stub!(:stubable_cache_get).and_raise('IO timeout')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has no errors by default" do
|
17
|
+
cache.read_error_occurred.should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "catches timeout errors" do
|
21
|
+
MemCache.read_error_callback = lambda{}
|
22
|
+
simulate_timeout
|
23
|
+
cache.get('x').should == nil
|
24
|
+
cache.read_error_occurred.should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "resets error_occurred to false after successful get" do
|
28
|
+
MemCache.read_error_callback = lambda{}
|
29
|
+
simulate_timeout
|
30
|
+
cache.get('x').should == nil
|
31
|
+
cache.stub!(:stubable_cache_get).and_return 1
|
32
|
+
cache.get('x').should == 1
|
33
|
+
cache.read_error_occurred.should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises if no callback is given" do
|
37
|
+
simulate_timeout
|
38
|
+
lambda{
|
39
|
+
cache.get('x').should == nil
|
40
|
+
}.should raise_error
|
41
|
+
cache.read_error_occurred.should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "calls the callback" do
|
45
|
+
MemCache.read_error_callback = lambda{ 1 }
|
46
|
+
simulate_timeout
|
47
|
+
cache.get('x').should == 1
|
48
|
+
cache.read_error_occurred.should == true
|
49
|
+
end
|
50
|
+
end
|
@@ -1,35 +1,9 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
class TestMemcached
|
4
|
-
def initialize
|
5
|
-
@wrapped = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def set(key, object, ttl = nil)
|
9
|
-
raise 'nope!' if ttl.is_a? Hash or (ttl and not ttl.is_a? Numeric)
|
10
|
-
@wrapped[key] = object
|
11
|
-
end
|
12
|
-
|
13
|
-
def get(key)
|
14
|
-
@wrapped[key]
|
15
|
-
end
|
16
|
-
|
17
|
-
def [](x)
|
18
|
-
@wrapped[x]
|
19
|
-
end
|
20
|
-
|
21
|
-
def clear
|
22
|
-
@wrapped.clear
|
23
|
-
end
|
24
|
-
|
25
|
-
def delete(key)
|
26
|
-
@wrapped.delete(key)
|
27
|
-
end
|
28
|
-
end
|
2
|
+
require 'spec/mem_cache'
|
29
3
|
|
30
4
|
describe "Cachy::MemcachedWrapper" do
|
31
5
|
before :all do
|
32
|
-
@cache =
|
6
|
+
@cache = MemCache.new
|
33
7
|
Cachy.cache_store = @cache
|
34
8
|
end
|
35
9
|
|
data/spec/mem_cache.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# stub to test memcache integration
|
2
|
+
class MemCache
|
3
|
+
def initialize
|
4
|
+
@wrapped = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def set(key, object, ttl = nil)
|
8
|
+
raise 'nope!' if ttl.is_a? Hash or (ttl and not ttl.is_a? Numeric)
|
9
|
+
@wrapped[key] = object
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(key)
|
13
|
+
cache_get(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def cache_get(key)
|
17
|
+
stubable_cache_get(key)
|
18
|
+
end
|
19
|
+
|
20
|
+
def stubable_cache_get(key)
|
21
|
+
@wrapped[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](x)
|
25
|
+
@wrapped[x]
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear
|
29
|
+
@wrapped.clear
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete(key)
|
33
|
+
@wrapped.delete(key)
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Grosser
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-18 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -37,10 +37,12 @@ files:
|
|
37
37
|
- lib/cachy/moneta_wrapper.rb
|
38
38
|
- lib/cachy/redis_wrapper.rb
|
39
39
|
- lib/cachy/wrapper.rb
|
40
|
+
- spec/cachy/memcache_timeout_protection_spec.rb
|
40
41
|
- spec/cachy/memcached_wrapper_spec.rb
|
41
42
|
- spec/cachy/moneta_wrapper_spec.rb
|
42
43
|
- spec/cachy/redis_wrapper_spec.rb
|
43
44
|
- spec/cachy_spec.rb
|
45
|
+
- spec/mem_cache.rb
|
44
46
|
- spec/spec_helper.rb
|
45
47
|
- spec/test_cache.rb
|
46
48
|
has_rdoc: true
|
@@ -76,7 +78,9 @@ summary: Caching library for projects that have many processes or many caches
|
|
76
78
|
test_files:
|
77
79
|
- spec/cachy/memcached_wrapper_spec.rb
|
78
80
|
- spec/cachy/moneta_wrapper_spec.rb
|
81
|
+
- spec/cachy/memcache_timeout_protection_spec.rb
|
79
82
|
- spec/cachy/redis_wrapper_spec.rb
|
83
|
+
- spec/mem_cache.rb
|
80
84
|
- spec/cachy_spec.rb
|
81
85
|
- spec/test_cache.rb
|
82
86
|
- spec/spec_helper.rb
|