mcmire-cache 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG +21 -0
  3. data/Gemfile +22 -0
  4. data/README.md +229 -0
  5. data/Rakefile +41 -0
  6. data/benchmarks/afterrefactor.txt +86 -0
  7. data/benchmarks/midrefactor.txt +89 -0
  8. data/benchmarks/v0.0.2.txt +95 -0
  9. data/benchmarks/v0.0.3.txt +96 -0
  10. data/benchmarks/v0.1.2.txt +94 -0
  11. data/benchmarks/v0.2.1.txt +94 -0
  12. data/benchmarks/v0.2.2.txt +94 -0
  13. data/lib/cache.rb +233 -0
  14. data/lib/cache/active_support_cache_dalli_store.rb +15 -0
  15. data/lib/cache/active_support_cache_file_store.rb +11 -0
  16. data/lib/cache/active_support_cache_memory_store.rb +11 -0
  17. data/lib/cache/active_support_cache_store.rb +37 -0
  18. data/lib/cache/config.rb +27 -0
  19. data/lib/cache/dalli_client.rb +54 -0
  20. data/lib/cache/mem_cache.rb +46 -0
  21. data/lib/cache/memcached.rb +54 -0
  22. data/lib/cache/memcached_rails.rb +34 -0
  23. data/lib/cache/nothing.rb +20 -0
  24. data/lib/cache/redis.rb +44 -0
  25. data/lib/cache/redis_namespace.rb +7 -0
  26. data/lib/cache/version.rb +3 -0
  27. data/mcmire-cache.gemspec +22 -0
  28. data/test/helper.rb +29 -0
  29. data/test/profile/benchmark.rb +258 -0
  30. data/test/shared_tests.rb +169 -0
  31. data/test/test_active_support_cache_dalli_store.rb +77 -0
  32. data/test/test_active_support_cache_file_store.rb +19 -0
  33. data/test/test_active_support_cache_memory_store.rb +12 -0
  34. data/test/test_dalli_client.rb +70 -0
  35. data/test/test_mem_cache.rb +64 -0
  36. data/test/test_memcached.rb +64 -0
  37. data/test/test_memcached_rails.rb +61 -0
  38. data/test/test_memcached_with_binary.rb +17 -0
  39. data/test/test_missing_driver.rb +16 -0
  40. data/test/test_nothing.rb +147 -0
  41. data/test/test_redis.rb +60 -0
  42. data/test/test_redis_namespace.rb +64 -0
  43. metadata +108 -0
@@ -0,0 +1,60 @@
1
+ require 'helper'
2
+
3
+ require 'redis'
4
+ require 'uri'
5
+
6
+ class TestRedis < TestCase
7
+ def raw_client_class
8
+ Redis
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'
24
+
25
+ # get the main thread's ring
26
+ main_thread_redis_client_connection_socket_id = get_redis_client_connection_socket_id
27
+
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
31
+
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
34
+
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
38
+
39
+ def test_treats_as_not_fork_safe
40
+ # make sure ring is initialized
41
+ cache.get 'hi'
42
+
43
+ # get the main thread's ring
44
+ parent_process_redis_client_connection_socket_id = get_redis_client_connection_socket_id
45
+
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
49
+
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
54
+ end
55
+ Process.wait pid
56
+
57
+ # make sure it didn't raise
58
+ assert $?.success?
59
+ end
60
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ require 'redis'
4
+ require 'redis-namespace'
5
+
6
+ class TestRedisNamespaceStorage < TestCase
7
+ def raw_client_class
8
+ Redis::Namespace
9
+ end
10
+
11
+ def raw_client
12
+ raw_client_class.new(:test_cache, :redis => Redis.new)
13
+ end
14
+
15
+ include SharedTests
16
+
17
+ # client DOT client
18
+ def get_redis_client_connection_socket_id
19
+ connection = cache.metal.client.instance_variable_get :@connection
20
+ sock = connection.instance_variable_get(:@sock)
21
+ # $stderr.puts sock.inspect
22
+ sock.object_id
23
+ end
24
+
25
+ def test_treats_as_thread_safe
26
+ # make sure ring is initialized
27
+ cache.get 'hi'
28
+
29
+ # get the main thread's ring
30
+ main_thread_redis_client_connection_socket_id = get_redis_client_connection_socket_id
31
+
32
+ # sanity check that it's not changing every time
33
+ cache.get 'hi'
34
+ assert_equal main_thread_redis_client_connection_socket_id, get_redis_client_connection_socket_id
35
+
36
+ # create a new thread and get its ring
37
+ new_thread_redis_client_connection_socket_id = Thread.new { cache.get 'hi'; get_redis_client_connection_socket_id }.value
38
+
39
+ # make sure the ring was reinitialized
40
+ assert_equal main_thread_redis_client_connection_socket_id, new_thread_redis_client_connection_socket_id
41
+ end
42
+
43
+ def test_treats_as_not_fork_safe
44
+ # make sure ring is initialized
45
+ cache.get 'hi'
46
+
47
+ # get the main thread's ring
48
+ parent_process_redis_client_connection_socket_id = get_redis_client_connection_socket_id
49
+
50
+ # sanity check that it's not changing every time
51
+ cache.get 'hi'
52
+ assert_equal parent_process_redis_client_connection_socket_id, get_redis_client_connection_socket_id
53
+
54
+ # fork a new process
55
+ pid = Kernel.fork do
56
+ cache.get 'hi'
57
+ raise "Didn't split!" if parent_process_redis_client_connection_socket_id == get_redis_client_connection_socket_id
58
+ end
59
+ Process.wait pid
60
+
61
+ # make sure it didn't raise
62
+ assert $?.success?
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcmire-cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Seamus Abshere
9
+ - Christoph Grabo
10
+ - Elliot Winkler
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-08-22 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: Wraps memcached, redis(-namespace), memcache-client, dalli and handles
17
+ their weirdnesses, including forking
18
+ email:
19
+ - seamus@abshere.net
20
+ - chris@dinarrr.com
21
+ - elliot.winkler@gmail.com
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - .gitignore
27
+ - CHANGELOG
28
+ - Gemfile
29
+ - README.md
30
+ - Rakefile
31
+ - benchmarks/afterrefactor.txt
32
+ - benchmarks/midrefactor.txt
33
+ - benchmarks/v0.0.2.txt
34
+ - benchmarks/v0.0.3.txt
35
+ - benchmarks/v0.1.2.txt
36
+ - benchmarks/v0.2.1.txt
37
+ - benchmarks/v0.2.2.txt
38
+ - lib/cache.rb
39
+ - lib/cache/active_support_cache_dalli_store.rb
40
+ - lib/cache/active_support_cache_file_store.rb
41
+ - lib/cache/active_support_cache_memory_store.rb
42
+ - lib/cache/active_support_cache_store.rb
43
+ - lib/cache/config.rb
44
+ - lib/cache/dalli_client.rb
45
+ - lib/cache/mem_cache.rb
46
+ - lib/cache/memcached.rb
47
+ - lib/cache/memcached_rails.rb
48
+ - lib/cache/nothing.rb
49
+ - lib/cache/redis.rb
50
+ - lib/cache/redis_namespace.rb
51
+ - lib/cache/version.rb
52
+ - mcmire-cache.gemspec
53
+ - test/helper.rb
54
+ - test/profile/benchmark.rb
55
+ - test/shared_tests.rb
56
+ - test/test_active_support_cache_dalli_store.rb
57
+ - test/test_active_support_cache_file_store.rb
58
+ - test/test_active_support_cache_memory_store.rb
59
+ - test/test_dalli_client.rb
60
+ - test/test_mem_cache.rb
61
+ - test/test_memcached.rb
62
+ - test/test_memcached_rails.rb
63
+ - test/test_memcached_with_binary.rb
64
+ - test/test_missing_driver.rb
65
+ - test/test_nothing.rb
66
+ - test/test_redis.rb
67
+ - test/test_redis_namespace.rb
68
+ homepage: https://github.com/seamusabshere/cache
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: cache
88
+ rubygems_version: 1.8.23
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A unified cache handling interface inspired by libraries like ActiveSupport::Cache::Store,
92
+ Perl's Cache::Cache, CHI, etc.
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/profile/benchmark.rb
96
+ - test/shared_tests.rb
97
+ - test/test_active_support_cache_dalli_store.rb
98
+ - test/test_active_support_cache_file_store.rb
99
+ - test/test_active_support_cache_memory_store.rb
100
+ - test/test_dalli_client.rb
101
+ - test/test_mem_cache.rb
102
+ - test/test_memcached.rb
103
+ - test/test_memcached_rails.rb
104
+ - test/test_memcached_with_binary.rb
105
+ - test/test_missing_driver.rb
106
+ - test/test_nothing.rb
107
+ - test/test_redis.rb
108
+ - test/test_redis_namespace.rb