cache 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'redis'
27
27
  s.add_development_dependency 'redis-namespace'
28
28
  s.add_development_dependency 'dalli'
29
+ # https://github.com/fauna/memcached/pull/50
29
30
  s.add_development_dependency 'memcached', '<=1.2.6'
30
31
  s.add_development_dependency 'memcache-client'
31
32
  s.add_development_dependency 'rake'
@@ -19,11 +19,7 @@ class Cache
19
19
  # raw_client = Memcached.new('127.0.0.1:11211')
20
20
  # cache = Cache.wrap raw_client
21
21
  def self.wrap(client = nil)
22
- if client.is_a?(::Cache)
23
- client
24
- else
25
- new client
26
- end
22
+ new client
27
23
  end
28
24
 
29
25
  def initialize(client = nil) #:nodoc:
@@ -18,14 +18,18 @@ class Cache
18
18
  # Example:
19
19
  # cache.config.client = Memcached.new '127.0.0.1:11211'
20
20
  def client=(client) #:nodoc:
21
- @client = client
21
+ @client = client.is_a?(::Cache) ? client.config.client : client
22
22
  end
23
23
 
24
24
  def client #:nodoc:
25
25
  if @client.nil?
26
- require 'active_support/cache'
27
- require 'active_support/cache/memory_store'
28
- @client = ::ActiveSupport::Cache::MemoryStore.new
26
+ self.client = if defined?(::Rails) and ::Rails.respond_to?(:cache) and rails_cache = ::Rails.cache and not rails_cache.is_a?(::Cache)
27
+ rails_cache
28
+ else
29
+ require 'active_support/cache'
30
+ require 'active_support/cache/memory_store'
31
+ ::ActiveSupport::Cache::MemoryStore.new
32
+ end
29
33
  else
30
34
  @client
31
35
  end
@@ -1,4 +1,4 @@
1
1
  class Cache
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
4
4
 
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  module SharedTests
2
4
  def test_get
3
5
  assert_equal nil, @cache.get('hello')
@@ -152,4 +154,12 @@ module SharedTests
152
154
  @cache.set 'privyet', 'mir'
153
155
  assert_equal({ 'hello' => 'world', 'privyet' => 'mir'}, @cache.get_multi('hello', 'privyet', 'yoyoyo'))
154
156
  end
157
+
158
+ # https://github.com/fauna/memcached/pull/50
159
+ def test_get_set_behavior
160
+ @cache.flush
161
+ @cache.get 'get_set'
162
+ @cache.set 'get_set', 'go'
163
+ assert_equal 'go', @cache.get('get_set')
164
+ end
155
165
  end
@@ -1,8 +1,5 @@
1
1
  require 'helper'
2
2
 
3
- require 'active_support/cache'
4
- require 'active_support/cache/memory_store'
5
-
6
3
  class TestDefaultStorage < Test::Unit::TestCase
7
4
  def raw_client
8
5
  nil
@@ -11,6 +8,26 @@ class TestDefaultStorage < Test::Unit::TestCase
11
8
  def test_query
12
9
  assert @cache.storage.send(:memory_store?)
13
10
  end
14
-
11
+
12
+ def test_default
13
+ c = Cache.new
14
+ assert_equal ActiveSupport::Cache::MemoryStore, c.config.client.class
15
+ end
16
+
17
+ def test_self_reference
18
+ c = Cache.new(Cache.new)
19
+ assert_equal ActiveSupport::Cache::MemoryStore, c.config.client.class
20
+ end
21
+
22
+ def test_wrap_with_default
23
+ c = Cache.wrap(Cache.new)
24
+ assert_equal ActiveSupport::Cache::MemoryStore, c.config.client.class
25
+ end
26
+
27
+ def test_absurd_wrap
28
+ c = Cache.new(Cache.wrap(Cache.new))
29
+ assert_equal ActiveSupport::Cache::MemoryStore, c.config.client.class
30
+ end
31
+
15
32
  include SharedTests
16
33
  end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ require 'memcached'
4
+
5
+ class TestMemcachedBinaryStorage < Test::Unit::TestCase
6
+ def raw_client
7
+ Memcached.new 'localhost:11211', :support_cas => true, :binary => true
8
+ end
9
+
10
+ include SharedTests
11
+ end
@@ -0,0 +1,65 @@
1
+ require 'helper'
2
+
3
+ require 'active_support/cache'
4
+ require 'active_support/cache/memory_store'
5
+
6
+ class TestRailsCacheStorage < Test::Unit::TestCase
7
+ def setup
8
+ eval %{
9
+ module ::Rails
10
+ def self.cache
11
+ @cache || :deadbeef
12
+ end
13
+ def self.cache=(foo)
14
+ @cache = foo
15
+ end
16
+ end
17
+ }
18
+ end
19
+
20
+ def teardown
21
+ Object.send(:remove_const, :Rails)
22
+ end
23
+
24
+ def test_defaults_to_rails_cache
25
+ assert_equal :deadbeef, Cache.new.config.client
26
+ end
27
+
28
+ def test_helpful_default
29
+ Rails.cache = Cache.new
30
+ assert_equal ActiveSupport::Cache::MemoryStore, Rails.cache.config.client.class
31
+ end
32
+
33
+ def test_explicitly_set
34
+ c = Cache.new(Rails.cache)
35
+ assert_equal :deadbeef, c.config.client
36
+ end
37
+
38
+ def test_explicitly_set_2
39
+ c = Cache.new
40
+ c.config.client = Rails.cache
41
+ assert_equal :deadbeef, c.config.client
42
+ end
43
+
44
+ # these behave strangely because they resolve the value of Rails.cache (e.g., :deadbeef) before returning
45
+ def test_silly_self_reference
46
+ Rails.cache = Cache.new(Rails.cache)
47
+ assert_equal :deadbeef, Rails.cache.config.client
48
+ end
49
+
50
+ def test_self_reference_twice
51
+ Rails.cache = Cache.new(Cache.new)
52
+ assert_equal :deadbeef, Rails.cache.config.client
53
+ end
54
+
55
+ def test_self_reference_with_wrap
56
+ Rails.cache = Cache.wrap(Cache.new)
57
+ assert_equal :deadbeef, Rails.cache.config.client
58
+ end
59
+
60
+ def test_self_reference_with_absurd_wrapping
61
+ Rails.cache = Cache.new(Cache.wrap(Cache.new))
62
+ assert_equal :deadbeef, Rails.cache.config.client
63
+ end
64
+ #--
65
+ 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.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-13 00:00:00.000000000Z
13
+ date: 2011-07-27 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2154119360 !ruby/object:Gem::Requirement
17
+ requirement: &2152957540 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.11
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2154119360
25
+ version_requirements: *2152957540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: i18n
28
- requirement: &2154118940 !ruby/object:Gem::Requirement
28
+ requirement: &2152957040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2154118940
36
+ version_requirements: *2152957040
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: yard
39
- requirement: &2154118480 !ruby/object:Gem::Requirement
39
+ requirement: &2152956460 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2154118480
47
+ version_requirements: *2152956460
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: test-unit
50
- requirement: &2154118060 !ruby/object:Gem::Requirement
50
+ requirement: &2152955960 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2154118060
58
+ version_requirements: *2152955960
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: redis
61
- requirement: &2154117640 !ruby/object:Gem::Requirement
61
+ requirement: &2152955420 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2154117640
69
+ version_requirements: *2152955420
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: redis-namespace
72
- requirement: &2154117220 !ruby/object:Gem::Requirement
72
+ requirement: &2152954880 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2154117220
80
+ version_requirements: *2152954880
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: dalli
83
- requirement: &2154116800 !ruby/object:Gem::Requirement
83
+ requirement: &2152954380 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2154116800
91
+ version_requirements: *2152954380
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: memcached
94
- requirement: &2154116300 !ruby/object:Gem::Requirement
94
+ requirement: &2152953800 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - <=
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 1.2.6
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2154116300
102
+ version_requirements: *2152953800
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: memcache-client
105
- requirement: &2154115880 !ruby/object:Gem::Requirement
105
+ requirement: &2152953300 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *2154115880
113
+ version_requirements: *2152953300
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rake
116
- requirement: &2154115420 !ruby/object:Gem::Requirement
116
+ requirement: &2152952760 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,7 +121,7 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *2154115420
124
+ version_requirements: *2152952760
125
125
  description: Wraps memcached, redis(-namespace), memcache-client, dalli and handles
126
126
  their weirdnesses, including forking
127
127
  email:
@@ -152,8 +152,10 @@ files:
152
152
  - test/test_dalli_store_storage.rb
153
153
  - test/test_default_storage.rb
154
154
  - test/test_memcache_storage.rb
155
+ - test/test_memcached_binary_storage.rb
155
156
  - test/test_memcached_rails_storage.rb
156
157
  - test/test_memcached_storage.rb
158
+ - test/test_rails_cache_storage.rb
157
159
  - test/test_redis_storage.rb
158
160
  homepage: https://github.com/seamusabshere/cache
159
161
  licenses: []
@@ -188,6 +190,8 @@ test_files:
188
190
  - test/test_dalli_store_storage.rb
189
191
  - test/test_default_storage.rb
190
192
  - test/test_memcache_storage.rb
193
+ - test/test_memcached_binary_storage.rb
191
194
  - test/test_memcached_rails_storage.rb
192
195
  - test/test_memcached_storage.rb
196
+ - test/test_rails_cache_storage.rb
193
197
  - test/test_redis_storage.rb