cache 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/Gemfile +3 -1
- data/lib/cache.rb +1 -1
- data/lib/cache/config.rb +0 -7
- data/lib/cache/redis.rb +9 -3
- data/lib/cache/redis_namespace.rb +1 -1
- data/lib/cache/version.rb +1 -1
- data/test/test_memcached_binary_storage.rb +8 -6
- data/test/test_memcached_rails_storage.rb +47 -45
- data/test/test_memcached_storage.rb +49 -47
- data/test/test_rails_cache_storage.rb +9 -9
- data/test/test_redis_namespace_storage.rb +61 -0
- data/test/test_redis_storage.rb +46 -49
- metadata +4 -2
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/lib/cache.rb
CHANGED
data/lib/cache/config.rb
CHANGED
data/lib/cache/redis.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
module Cache::Redis
|
2
|
+
def after_fork
|
3
|
+
@metal.quit
|
4
|
+
end
|
5
|
+
|
2
6
|
def _get(k)
|
3
7
|
if cached_v = @metal.get(k) and cached_v.is_a?(::String)
|
4
8
|
::Marshal.load cached_v
|
@@ -7,7 +11,9 @@ module Cache::Redis
|
|
7
11
|
|
8
12
|
def _get_multi(ks)
|
9
13
|
ks.inject({}) do |memo, k|
|
10
|
-
|
14
|
+
if v = _get(k)
|
15
|
+
memo[k] = v
|
16
|
+
end
|
11
17
|
memo
|
12
18
|
end
|
13
19
|
end
|
@@ -25,7 +31,7 @@ module Cache::Redis
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def _flush
|
28
|
-
@metal.
|
34
|
+
@metal.flushdb
|
29
35
|
end
|
30
36
|
|
31
37
|
def _exist?(k)
|
@@ -33,6 +39,6 @@ module Cache::Redis
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def _stats
|
36
|
-
@metal.
|
42
|
+
@metal.info
|
37
43
|
end
|
38
44
|
end
|
data/lib/cache/version.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
3
|
+
unless RUBY_PLATFORM == 'java'
|
4
|
+
require 'memcached'
|
4
5
|
|
5
|
-
class TestMemcachedBinaryStorage < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
6
|
+
class TestMemcachedBinaryStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
Memcached.new 'localhost:11211', :support_cas => true, :binary => true
|
9
|
+
end
|
10
|
+
|
11
|
+
include SharedTests
|
8
12
|
end
|
9
|
-
|
10
|
-
include SharedTests
|
11
13
|
end
|
@@ -1,55 +1,57 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
3
|
+
unless RUBY_PLATFORM == 'java'
|
4
|
+
require 'memcached'
|
4
5
|
|
5
|
-
class TestMemcachedRailsStorage < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def get_bare_id
|
13
|
-
@cache.thread_metal.object_id
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_treats_as_not_thread_safe
|
17
|
-
# make sure bare client is initialized
|
18
|
-
@cache.get 'hi'
|
19
|
-
|
20
|
-
# get the main thread's bare client
|
21
|
-
main_thread_bare_id = get_bare_id
|
22
|
-
|
23
|
-
# sanity check that it's not changing every time
|
24
|
-
@cache.get 'hi'
|
25
|
-
assert_equal main_thread_bare_id, get_bare_id
|
26
|
-
|
27
|
-
# create a new thread and get its bare client
|
28
|
-
new_thread_bare_id = Thread.new { @cache.get 'hi'; get_bare_id }.value
|
29
|
-
|
30
|
-
# make sure the bare client was reinitialized
|
31
|
-
assert(main_thread_bare_id != new_thread_bare_id)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_treats_as_not_fork_safe
|
35
|
-
# make sure bare client is initialized
|
36
|
-
@cache.get 'hi'
|
37
|
-
|
38
|
-
# get the main process's bare client
|
39
|
-
parent_process_bare_id = get_bare_id
|
6
|
+
class TestMemcachedRailsStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
Memcached::Rails.new 'localhost:11211', :support_cas => true
|
9
|
+
end
|
10
|
+
|
11
|
+
include SharedTests
|
40
12
|
|
41
|
-
|
42
|
-
|
43
|
-
|
13
|
+
def get_bare_id
|
14
|
+
@cache.thread_metal.object_id
|
15
|
+
end
|
44
16
|
|
45
|
-
|
46
|
-
|
17
|
+
def test_treats_as_not_thread_safe
|
18
|
+
# make sure bare client is initialized
|
19
|
+
@cache.get 'hi'
|
20
|
+
|
21
|
+
# get the main thread's bare client
|
22
|
+
main_thread_bare_id = get_bare_id
|
23
|
+
|
24
|
+
# sanity check that it's not changing every time
|
47
25
|
@cache.get 'hi'
|
48
|
-
|
26
|
+
assert_equal main_thread_bare_id, get_bare_id
|
27
|
+
|
28
|
+
# create a new thread and get its bare client
|
29
|
+
new_thread_bare_id = Thread.new { @cache.get 'hi'; get_bare_id }.value
|
30
|
+
|
31
|
+
# make sure the bare client was reinitialized
|
32
|
+
assert(main_thread_bare_id != new_thread_bare_id)
|
49
33
|
end
|
50
|
-
Process.wait pid
|
51
34
|
|
52
|
-
|
53
|
-
|
35
|
+
def test_treats_as_not_fork_safe
|
36
|
+
# make sure bare client is initialized
|
37
|
+
@cache.get 'hi'
|
38
|
+
|
39
|
+
# get the main process's bare client
|
40
|
+
parent_process_bare_id = get_bare_id
|
41
|
+
|
42
|
+
# sanity check that it's not changing every time
|
43
|
+
@cache.get 'hi'
|
44
|
+
assert_equal parent_process_bare_id, get_bare_id
|
45
|
+
|
46
|
+
# fork a new process
|
47
|
+
pid = Kernel.fork do
|
48
|
+
@cache.get 'hi'
|
49
|
+
raise "Didn't split!" if parent_process_bare_id == get_bare_id
|
50
|
+
end
|
51
|
+
Process.wait pid
|
52
|
+
|
53
|
+
# make sure it didn't raise
|
54
|
+
assert $?.success?
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,58 +1,60 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
3
|
+
unless RUBY_PLATFORM == 'java'
|
4
|
+
require 'memcached'
|
4
5
|
|
5
|
-
class TestMemcachedStorage < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def get_bare_id
|
13
|
-
@cache.thread_metal.object_id
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_treats_as_not_thread_safe
|
17
|
-
# make sure bare client is initialized
|
18
|
-
@cache.get 'hi'
|
19
|
-
|
20
|
-
# get the main thread's bare client
|
21
|
-
main_thread_bare_id = get_bare_id
|
22
|
-
|
23
|
-
# sanity check that it's not changing every time
|
24
|
-
@cache.get 'hi'
|
25
|
-
assert_equal main_thread_bare_id, get_bare_id
|
6
|
+
class TestMemcachedStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
Memcached.new 'localhost:11211', :support_cas => true
|
9
|
+
end
|
10
|
+
|
11
|
+
include SharedTests
|
26
12
|
|
27
|
-
|
28
|
-
|
13
|
+
def get_bare_id
|
14
|
+
@cache.thread_metal.object_id
|
15
|
+
end
|
29
16
|
|
30
|
-
|
31
|
-
|
17
|
+
def test_treats_as_not_thread_safe
|
18
|
+
# make sure bare client is initialized
|
19
|
+
@cache.get 'hi'
|
20
|
+
|
21
|
+
# get the main thread's bare client
|
22
|
+
main_thread_bare_id = get_bare_id
|
23
|
+
|
24
|
+
# sanity check that it's not changing every time
|
25
|
+
@cache.get 'hi'
|
26
|
+
assert_equal main_thread_bare_id, get_bare_id
|
27
|
+
|
28
|
+
# create a new thread and get its bare client
|
29
|
+
new_thread_bare_id = Thread.new { @cache.get 'hi'; get_bare_id }.value
|
30
|
+
|
31
|
+
# make sure the bare client was reinitialized
|
32
|
+
assert(main_thread_bare_id != new_thread_bare_id)
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def test_treats_as_not_fork_safe
|
38
|
-
# make sure bare client is initialized
|
39
|
-
@cache.get 'hi'
|
40
|
-
|
41
|
-
# get the main process's bare client
|
42
|
-
parent_process_bare_id = get_bare_id
|
43
|
-
|
44
|
-
# sanity check that it's not changing every time
|
45
|
-
@cache.get 'hi'
|
46
|
-
assert_equal parent_process_bare_id, get_bare_id
|
34
|
+
# make sure the main thread's client wasn't messed with
|
35
|
+
assert_equal main_thread_bare_id, get_bare_id
|
36
|
+
end
|
47
37
|
|
48
|
-
|
49
|
-
|
38
|
+
def test_treats_as_not_fork_safe
|
39
|
+
# make sure bare client is initialized
|
40
|
+
@cache.get 'hi'
|
41
|
+
|
42
|
+
# get the main process's bare client
|
43
|
+
parent_process_bare_id = get_bare_id
|
44
|
+
|
45
|
+
# sanity check that it's not changing every time
|
50
46
|
@cache.get 'hi'
|
51
|
-
|
47
|
+
assert_equal parent_process_bare_id, get_bare_id
|
48
|
+
|
49
|
+
# fork a new process
|
50
|
+
pid = Kernel.fork do
|
51
|
+
@cache.get 'hi'
|
52
|
+
raise "Didn't split!" if parent_process_bare_id == get_bare_id
|
53
|
+
end
|
54
|
+
Process.wait pid
|
55
|
+
|
56
|
+
# make sure it didn't raise
|
57
|
+
assert $?.success?
|
52
58
|
end
|
53
|
-
Process.wait pid
|
54
|
-
|
55
|
-
# make sure it didn't raise
|
56
|
-
assert $?.success?
|
57
59
|
end
|
58
60
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'dalli'
|
4
4
|
require 'active_support/cache'
|
5
5
|
require 'active_support/cache/memory_store'
|
6
6
|
|
@@ -9,7 +9,7 @@ class TestRailsCacheStorage < Test::Unit::TestCase
|
|
9
9
|
eval %{
|
10
10
|
module ::Rails
|
11
11
|
def self.cache
|
12
|
-
@cache ||
|
12
|
+
@cache || ActiveSupport::Cache::DalliStore.new(['localhost:11211'])
|
13
13
|
end
|
14
14
|
def self.cache=(foo)
|
15
15
|
@cache = foo
|
@@ -23,7 +23,7 @@ class TestRailsCacheStorage < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_defaults_to_rails_cache
|
26
|
-
assert_equal
|
26
|
+
assert_equal ActiveSupport::Cache::DalliStore, Cache.new.metal.class
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_helpful_default
|
@@ -40,28 +40,28 @@ class TestRailsCacheStorage < Test::Unit::TestCase
|
|
40
40
|
|
41
41
|
def test_explicitly_set
|
42
42
|
c = Cache.new(Rails.cache)
|
43
|
-
assert_equal
|
43
|
+
assert_equal ActiveSupport::Cache::DalliStore, c.metal.class
|
44
44
|
end
|
45
45
|
|
46
|
-
# these behave strangely because they resolve the value of Rails.cache (e.g.,
|
46
|
+
# these behave strangely because they resolve the value of Rails.cache (e.g., ActiveSupport::Cache::DalliStore) before returning
|
47
47
|
def test_silly_self_reference
|
48
48
|
Rails.cache = Cache.new(Rails.cache)
|
49
|
-
assert_equal
|
49
|
+
assert_equal ActiveSupport::Cache::DalliStore, Rails.cache.metal.class
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_self_reference_twice
|
53
53
|
Rails.cache = Cache.new(Cache.new)
|
54
|
-
assert_equal
|
54
|
+
assert_equal ActiveSupport::Cache::DalliStore, Rails.cache.metal.class
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_self_reference_with_wrap
|
58
58
|
Rails.cache = Cache.wrap(Cache.new)
|
59
|
-
assert_equal
|
59
|
+
assert_equal ActiveSupport::Cache::DalliStore, Rails.cache.metal.class
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_self_reference_with_absurd_wrapping
|
63
63
|
Rails.cache = Cache.new(Cache.wrap(Cache.new))
|
64
|
-
assert_equal
|
64
|
+
assert_equal ActiveSupport::Cache::DalliStore, Rails.cache.metal.class
|
65
65
|
end
|
66
66
|
#--
|
67
67
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
require 'redis'
|
4
|
+
require 'redis-namespace'
|
5
|
+
|
6
|
+
class TestRedisNamespaceStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
r = Redis.new
|
9
|
+
Redis::Namespace.new(:test_cache, :redis => r)
|
10
|
+
end
|
11
|
+
|
12
|
+
include SharedTests
|
13
|
+
|
14
|
+
# client DOT client
|
15
|
+
def get_redis_client_connection_socket_id
|
16
|
+
connection = @cache.metal.client.instance_variable_get :@connection
|
17
|
+
sock = connection.instance_variable_get(:@sock)
|
18
|
+
# $stderr.puts sock.inspect
|
19
|
+
sock.object_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_treats_as_thread_safe
|
23
|
+
# make sure ring is initialized
|
24
|
+
@cache.get 'hi'
|
25
|
+
|
26
|
+
# get the main thread's ring
|
27
|
+
main_thread_redis_client_connection_socket_id = get_redis_client_connection_socket_id
|
28
|
+
|
29
|
+
# sanity check that it's not changing every time
|
30
|
+
@cache.get 'hi'
|
31
|
+
assert_equal main_thread_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
32
|
+
|
33
|
+
# create a new thread and get its ring
|
34
|
+
new_thread_redis_client_connection_socket_id = Thread.new { @cache.get 'hi'; get_redis_client_connection_socket_id }.value
|
35
|
+
|
36
|
+
# make sure the ring was reinitialized
|
37
|
+
assert_equal main_thread_redis_client_connection_socket_id, new_thread_redis_client_connection_socket_id
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_treats_as_not_fork_safe
|
41
|
+
# make sure ring is initialized
|
42
|
+
@cache.get 'hi'
|
43
|
+
|
44
|
+
# get the main thread's ring
|
45
|
+
parent_process_redis_client_connection_socket_id = get_redis_client_connection_socket_id
|
46
|
+
|
47
|
+
# sanity check that it's not changing every time
|
48
|
+
@cache.get 'hi'
|
49
|
+
assert_equal parent_process_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
50
|
+
|
51
|
+
# fork a new process
|
52
|
+
pid = Kernel.fork do
|
53
|
+
@cache.get 'hi'
|
54
|
+
raise "Didn't split!" if parent_process_redis_client_connection_socket_id == get_redis_client_connection_socket_id
|
55
|
+
end
|
56
|
+
Process.wait pid
|
57
|
+
|
58
|
+
# make sure it didn't raise
|
59
|
+
assert $?.success?
|
60
|
+
end
|
61
|
+
end
|
data/test/test_redis_storage.rb
CHANGED
@@ -1,63 +1,60 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'uri'
|
6
|
-
|
7
|
-
class TestRedisStorage < Test::Unit::TestCase
|
8
|
-
def raw_client
|
9
|
-
uri = URI.parse(ENV["REDIS_URL"])
|
10
|
-
Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
|
11
|
-
end
|
12
|
-
|
13
|
-
include SharedTests
|
14
|
-
|
15
|
-
# client DOT client
|
16
|
-
def get_redis_client_connection_socket_id
|
17
|
-
connection = @cache.metal.client.instance_variable_get :@connection
|
18
|
-
sock = connection.instance_variable_get(:@sock)
|
19
|
-
# $stderr.puts sock.inspect
|
20
|
-
sock.object_id
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_treats_as_thread_safe
|
24
|
-
# make sure ring is initialized
|
25
|
-
@cache.get 'hi'
|
3
|
+
require 'redis'
|
4
|
+
require 'uri'
|
26
5
|
|
27
|
-
|
28
|
-
|
6
|
+
class TestRedisStorage < Test::Unit::TestCase
|
7
|
+
def raw_client
|
8
|
+
Redis.new#(:host => uri.host, :port => uri.port, :password => uri.password)
|
9
|
+
end
|
10
|
+
|
11
|
+
include SharedTests
|
12
|
+
|
13
|
+
# client DOT client
|
14
|
+
def get_redis_client_connection_socket_id
|
15
|
+
connection = @cache.metal.client.instance_variable_get :@connection
|
16
|
+
sock = connection.instance_variable_get(:@sock)
|
17
|
+
# $stderr.puts sock.inspect
|
18
|
+
sock.object_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_treats_as_thread_safe
|
22
|
+
# make sure ring is initialized
|
23
|
+
@cache.get 'hi'
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal main_thread_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
25
|
+
# get the main thread's ring
|
26
|
+
main_thread_redis_client_connection_socket_id = get_redis_client_connection_socket_id
|
33
27
|
|
34
|
-
|
35
|
-
|
28
|
+
# sanity check that it's not changing every time
|
29
|
+
@cache.get 'hi'
|
30
|
+
assert_equal main_thread_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
32
|
+
# create a new thread and get its ring
|
33
|
+
new_thread_redis_client_connection_socket_id = Thread.new { @cache.get 'hi'; get_redis_client_connection_socket_id }.value
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
# make sure the ring was reinitialized
|
36
|
+
assert_equal main_thread_redis_client_connection_socket_id, new_thread_redis_client_connection_socket_id
|
37
|
+
end
|
44
38
|
|
45
|
-
|
46
|
-
|
39
|
+
def test_treats_as_not_fork_safe
|
40
|
+
# make sure ring is initialized
|
41
|
+
@cache.get 'hi'
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
assert_equal parent_process_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
43
|
+
# get the main thread's ring
|
44
|
+
parent_process_redis_client_connection_socket_id = get_redis_client_connection_socket_id
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
raise "Didn't split!" if parent_process_redis_client_connection_socket_id == get_redis_client_connection_socket_id
|
56
|
-
end
|
57
|
-
Process.wait pid
|
46
|
+
# sanity check that it's not changing every time
|
47
|
+
@cache.get 'hi'
|
48
|
+
assert_equal parent_process_redis_client_connection_socket_id, get_redis_client_connection_socket_id
|
58
49
|
|
59
|
-
|
60
|
-
|
50
|
+
# fork a new process
|
51
|
+
pid = Kernel.fork do
|
52
|
+
@cache.get 'hi'
|
53
|
+
raise "Didn't split!" if parent_process_redis_client_connection_socket_id == get_redis_client_connection_socket_id
|
61
54
|
end
|
55
|
+
Process.wait pid
|
56
|
+
|
57
|
+
# make sure it didn't raise
|
58
|
+
assert $?.success?
|
62
59
|
end
|
63
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- test/test_memcached_rails_storage.rb
|
92
92
|
- test/test_memcached_storage.rb
|
93
93
|
- test/test_rails_cache_storage.rb
|
94
|
+
- test/test_redis_namespace_storage.rb
|
94
95
|
- test/test_redis_storage.rb
|
95
96
|
homepage: https://github.com/seamusabshere/cache
|
96
97
|
licenses: []
|
@@ -130,5 +131,6 @@ test_files:
|
|
130
131
|
- test/test_memcached_rails_storage.rb
|
131
132
|
- test/test_memcached_storage.rb
|
132
133
|
- test/test_rails_cache_storage.rb
|
134
|
+
- test/test_redis_namespace_storage.rb
|
133
135
|
- test/test_redis_storage.rb
|
134
136
|
has_rdoc:
|