dsander-memcache-client 1.7.7.pre → 1.7.8.pre

Sign up to get free protection for your applications and to get access to all the features.
data/FAQ.rdoc CHANGED
@@ -27,5 +27,5 @@ You can increase the timeout or disable them completely with the following confi
27
27
 
28
28
  The latest version of memcached-client is anywhere from 33% to 100% slower than memcached in various benchmarks. Keep in mind this means that 10,000 get requests take 1.8 sec instead of 1.2 seconds.
29
29
  In practice, memcache-client is unlikely to be a bottleneck in your system but there is always going
30
- to be an overhead to pure Ruby. memcache-client does have the advantage of built-in integration into
30
+ to be an overhead to pure Ruby. memcache-client does have the advantage of built-in integration into
31
31
  Rails and should work on non-MRI platforms: JRuby, MacRuby, etc.
data/History.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ = 1.7.8 (HEAD)
2
+
3
+ * Fix issue where autofix_keys logic did not account for namespace length. (menno)
4
+ * Fix issue when using memcache-client without rubygems. (anvar)
5
+
6
+ = 1.7.7 (2009-11-24)
7
+
8
+ * Fix invalid delete request in memcached 1.4.x. The expiry parameter to MemCache#delete is
9
+ now ignored as memcached 1.4.x has dropped support for this feature.
10
+
1
11
  = 1.7.6 (2009-11-03)
2
12
 
3
13
  * Reworked socket timeout code due to several customer complaints about timeouts not
@@ -34,15 +44,15 @@
34
44
 
35
45
  = 1.7.1 (2009-03-28)
36
46
 
37
- * Performance optimizations:
38
- * Rely on higher performance operating system socket timeouts for low-level socket
47
+ * Performance optimizations:
48
+ * Rely on higher performance operating system socket timeouts for low-level socket
39
49
  read/writes where possible, instead of the (slower) SystemTimer or (slowest,
40
50
  unreliable) Timeout libraries.
41
- * the native binary search is back! The recent performance tuning made the binary search
42
- a bottleneck again so it had to return. It uses RubyInline to compile the native extension and
51
+ * the native binary search is back! The recent performance tuning made the binary search
52
+ a bottleneck again so it had to return. It uses RubyInline to compile the native extension and
43
53
  silently falls back to pure Ruby if anything fails. Make sure you run:
44
54
  `gem install RubyInline` if you want ultimate performance.
45
- * the changes make memcache-client 100% faster than 1.7.0 in my performance test on Ruby 1.8.6:
55
+ * the changes make memcache-client 100% faster than 1.7.0 in my performance test on Ruby 1.8.6:
46
56
  15 sec -> 8 sec.
47
57
  * Fix several logging issues.
48
58
 
@@ -53,7 +63,7 @@
53
63
  - append
54
64
  - prepend
55
65
  - replace
56
-
66
+
57
67
  Append and prepend only work with raw data since it makes no sense to concatenate two Marshalled
58
68
  values together. The cas functionality should be considered a prototype. Since I don't have an
59
69
  application which uses +cas+, I'm not sure what semantic sugar the API should provide. Should it
@@ -114,17 +124,17 @@ and work on JRuby and Ruby 1.8.5 when the native code fails to compile.
114
124
 
115
125
  = 1.6.1 (2009-01-28)
116
126
 
117
- * Add option to disable socket timeout support. Socket timeout has a significant performance
118
- penalty (approx 3x slower than without in Ruby 1.8.6). You can turn off the timeouts if you
127
+ * Add option to disable socket timeout support. Socket timeout has a significant performance
128
+ penalty (approx 3x slower than without in Ruby 1.8.6). You can turn off the timeouts if you
119
129
  need absolute performance, but by default timeouts are enabled. The performance
120
130
  penalty is much lower in Ruby 1.8.7, 1.9 and JRuby. (mperham)
121
131
 
122
- * Add option to disable server failover. Failover can lead to "split-brain" caches that
132
+ * Add option to disable server failover. Failover can lead to "split-brain" caches that
123
133
  return stale data. (mperham)
124
134
 
125
135
  * Implement continuum binary search in native code for performance reasons. Pure ruby
126
136
  is available for platforms like JRuby or Rubinius which can't use C extensions. (mperham)
127
-
137
+
128
138
  * Fix #add with raw=true (iamaleksey)
129
139
 
130
140
  = 1.6.0
data/README.rdoc CHANGED
@@ -39,7 +39,7 @@ gem installed.
39
39
 
40
40
  == Questions?
41
41
 
42
- memcache-client is maintained by Mike Perham and was originally written by Bob Cottrell,
42
+ memcache-client is maintained by Mike Perham and was originally written by Bob Cottrell,
43
43
  Eric Hodel and the seattle.rb crew.
44
44
 
45
45
  Email:: mailto:mperham@gmail.com
data/Rakefile CHANGED
@@ -23,9 +23,9 @@ end
23
23
 
24
24
 
25
25
  Rake::RDocTask.new do |rd|
26
- rd.main = "README.rdoc"
27
- rd.rdoc_files.include("README.rdoc", "FAQ.rdoc", "History.rdoc", "lib/memcache.rb")
28
- rd.rdoc_dir = 'doc'
26
+ rd.main = "README.rdoc"
27
+ rd.rdoc_files.include("README.rdoc", "FAQ.rdoc", "History.rdoc", "lib/memcache.rb")
28
+ rd.rdoc_dir = 'doc'
29
29
  end
30
30
 
31
31
  Rake::TestTask.new do |t|
data/VERSION.yml CHANGED
@@ -1,5 +1,4 @@
1
- ---
2
1
  :major: 1
3
2
  :minor: 7
4
- :patch: 7
3
+ :patch: 8
5
4
  :build: pre
data/lib/memcache.rb CHANGED
@@ -3,6 +3,7 @@ $TESTING = defined?($TESTING) && $TESTING
3
3
  require 'socket'
4
4
  require 'thread'
5
5
  require 'zlib'
6
+ require 'yaml'
6
7
  require 'digest/sha1'
7
8
  require 'net/protocol'
8
9
  require 'yaml'
@@ -84,13 +85,13 @@ class MemCache
84
85
  # The hash is only used on keys longer than 250 characters, or containing spaces,
85
86
  # to avoid impacting performance unnecesarily.
86
87
  #
87
- # In theory, your code should generate correct keys when calling memcache,
88
+ # In theory, your code should generate correct keys when calling memcache,
88
89
  # so it's your responsibility and you should try to fix this problem at its source.
89
90
  #
90
91
  # But if that's not possible, enable this option and memcache-client will give you a hand.
91
-
92
+
92
93
  attr_reader :autofix_keys
93
-
94
+
94
95
  ##
95
96
  # The servers this client talks to. Play at your own peril.
96
97
 
@@ -142,7 +143,7 @@ class MemCache
142
143
  # set/add/delete/incr/decr significantly.
143
144
  # [:check_size] Raises a MemCacheError if the value to be set is greater than 1 MB, which
144
145
  # is the maximum key size for the standard memcached server. Defaults to true.
145
- # [:autofix_keys] If a key is longer than 250 characters or contains spaces,
146
+ # [:autofix_keys] If a key is longer than 250 characters or contains spaces,
146
147
  # use an SHA1 hash instead, to prevent collisions on truncated keys.
147
148
  # Other options are ignored.
148
149
 
@@ -288,7 +289,7 @@ class MemCache
288
289
  end
289
290
 
290
291
  ##
291
- # Performs a +get+ with the given +key+. If
292
+ # Performs a +get+ with the given +key+. If
292
293
  # the value does not exist and a block was given,
293
294
  # the block will be called and the result saved via +add+.
294
295
  #
@@ -479,7 +480,7 @@ class MemCache
479
480
  end
480
481
  end
481
482
  end
482
-
483
+
483
484
  ##
484
485
  # Add +key+ to the cache with value +value+ that expires in +expiry+
485
486
  # seconds, but only if +key+ already exists in the cache.
@@ -542,14 +543,15 @@ class MemCache
542
543
  end
543
544
 
544
545
  ##
545
- # Removes +key+ from the cache in +expiry+ seconds.
546
+ # Removes +key+ from the cache.
547
+ # +expiry+ is ignored as it has been removed from the latest memcached version.
546
548
 
547
549
  def delete(key, expiry = 0)
548
550
  raise MemCacheError, "Update of readonly cache" if @readonly
549
551
  with_server(key) do |server, cache_key|
550
552
  with_socket_management(server) do |socket|
551
553
  logger.debug { "delete #{cache_key} on #{server}" } if logger
552
- socket.write "delete #{cache_key} #{expiry}#{noreply}\r\n"
554
+ socket.write "delete #{cache_key}#{noreply}\r\n"
553
555
  break nil if @no_reply
554
556
  result = socket.gets
555
557
  raise_on_error_response! result
@@ -694,17 +696,24 @@ class MemCache
694
696
  # requested.
695
697
 
696
698
  def make_cache_key(key)
697
- if @autofix_keys and (key =~ /\s/ or (key.length + (namespace.nil? ? 0 : namespace.length)) > 250)
699
+ if @autofix_keys && (key =~ /\s/ || key_length(key) > 250)
698
700
  key = "#{Digest::SHA1.hexdigest(key)}-autofixed"
699
701
  end
700
702
 
701
- if namespace.nil? then
703
+ if namespace.nil?
702
704
  key
703
705
  else
704
706
  "#{@namespace}#{@namespace_separator}#{key}"
705
707
  end
706
708
  end
707
709
 
710
+ ##
711
+ # Calculate length of the key, including the namespace and namespace-separator.
712
+
713
+ def key_length(key)
714
+ key.length + (namespace.nil? ? 0 : ( namespace.length + (@namespace_separator.nil? ? 0 : @namespace_separator.length) ) )
715
+ end
716
+
708
717
  ##
709
718
  # Returns an interoperable hash value for +key+. (I think, docs are
710
719
  # sketchy for down servers).
@@ -732,7 +741,7 @@ class MemCache
732
741
  break unless failover
733
742
  hkey = hash_for "#{try}#{key}"
734
743
  end
735
-
744
+
736
745
  raise MemCacheError, "No servers available"
737
746
  end
738
747
 
data/lib/memcache_util.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  ##
2
2
  # A utility wrapper around the MemCache client to simplify cache access. All
3
3
  # methods silently ignore MemCache errors.
4
- #
4
+ #
5
5
  # This API is deprecated, please use the Rails.cache API or your own wrapper API
6
6
  # around MemCache.
7
7
 
8
8
  module Cache
9
-
9
+
10
10
  ##
11
11
  # Try to return a logger object that does not rely
12
12
  # on ActiveRecord for logging.
@@ -17,7 +17,7 @@ class TestBenchmark < Test::Unit::TestCase
17
17
  # which is a constant penalty that both clients have to pay
18
18
  @value = []
19
19
  @marshalled = Marshal.dump(@value)
20
-
20
+
21
21
  @opts = [
22
22
  ['127.0.0.1:11211', 'localhost:11211'],
23
23
  {
@@ -31,16 +31,16 @@ class TestBenchmark < Test::Unit::TestCase
31
31
  @key3 = "Long"*40
32
32
  @key4 = "Medium"*8
33
33
  # 5 and 6 are only used for multiget miss test
34
- @key5 = "Medium2"*8
35
- @key6 = "Long3"*40
34
+ @key5 = "Medium2"*8
35
+ @key6 = "Long3"*40
36
36
  end
37
37
 
38
38
  def test_benchmark
39
39
  Benchmark.bm(31) do |x|
40
-
40
+
41
41
  n = 2500
42
42
  # n = 1000
43
-
43
+
44
44
  @m = MemCache.new(*@opts)
45
45
  x.report("set:plain:memcache-client") do
46
46
  n.times do
@@ -52,7 +52,7 @@ class TestBenchmark < Test::Unit::TestCase
52
52
  @m.set @key3, @marshalled, 0, true
53
53
  end
54
54
  end
55
-
55
+
56
56
  @m = MemCache.new(*@opts)
57
57
  x.report("set:ruby:memcache-client") do
58
58
  n.times do
@@ -64,7 +64,7 @@ class TestBenchmark < Test::Unit::TestCase
64
64
  @m.set @key3, @value
65
65
  end
66
66
  end
67
-
67
+
68
68
  @m = MemCache.new(*@opts)
69
69
  x.report("get:plain:memcache-client") do
70
70
  n.times do
@@ -76,7 +76,7 @@ class TestBenchmark < Test::Unit::TestCase
76
76
  @m.get @key3, true
77
77
  end
78
78
  end
79
-
79
+
80
80
  @m = MemCache.new(*@opts)
81
81
  x.report("get:ruby:memcache-client") do
82
82
  n.times do
@@ -96,7 +96,7 @@ class TestBenchmark < Test::Unit::TestCase
96
96
  @m.get_multi @key1, @key2, @key3, @key4, @key5, @key6
97
97
  end
98
98
  end
99
-
99
+
100
100
  @m = MemCache.new(*@opts)
101
101
  x.report("missing:ruby:memcache-client") do
102
102
  n.times do
@@ -108,7 +108,7 @@ class TestBenchmark < Test::Unit::TestCase
108
108
  begin @m.get @key3; rescue; end
109
109
  end
110
110
  end
111
-
111
+
112
112
  @m = MemCache.new(*@opts)
113
113
  x.report("mixed:ruby:memcache-client") do
114
114
  n.times do
@@ -20,7 +20,7 @@ class MemCache
20
20
 
21
21
  attr_writer :namespace
22
22
  attr_writer :autofix_keys
23
-
23
+
24
24
  end
25
25
 
26
26
  class FakeSocket
@@ -55,11 +55,11 @@ class Test::Unit::TestCase
55
55
  assert true
56
56
  end
57
57
  end
58
-
58
+
59
59
  def memcached_running?
60
60
  TCPSocket.new('localhost', 11211) rescue false
61
61
  end
62
-
62
+
63
63
  def xprofile(name, &block)
64
64
  a = Time.now
65
65
  block.call
@@ -77,7 +77,7 @@ class Test::Unit::TestCase
77
77
  end
78
78
  time
79
79
  end
80
-
80
+
81
81
  end
82
82
 
83
83
  class FakeServer
@@ -169,7 +169,7 @@ class TestMemCache < Test::Unit::TestCase
169
169
  assert same_count > 700
170
170
  end
171
171
  end
172
-
172
+
173
173
  def test_get_multi_with_server_failure
174
174
  @cache = MemCache.new 'localhost:1', :namespace => 'my_namespace', :gzip => false, :logger => nil #Logger.new(STDOUT)
175
175
  s1 = FakeServer.new
@@ -212,11 +212,11 @@ class TestMemCache < Test::Unit::TestCase
212
212
  assert s1.alive?
213
213
  assert !s2.alive?
214
214
  end
215
-
215
+
216
216
  def test_cache_get_without_failover
217
217
  s1 = FakeServer.new
218
218
  s2 = FakeServer.new
219
-
219
+
220
220
  s1.socket.data.write "VALUE foo 0 14\r\n\004\b\"\0170123456789\r\n"
221
221
  s1.socket.data.rewind
222
222
  s2.socket.data.write "bogus response\r\nbogus response\r\n"
@@ -505,7 +505,7 @@ class TestMemCache < Test::Unit::TestCase
505
505
  value = @cache.fetch('key', 1)
506
506
  assert_equal nil, value
507
507
  end
508
-
508
+
509
509
  def test_fetch_miss
510
510
  server = FakeServer.new
511
511
  server.socket.data.write "END\r\n"
@@ -741,29 +741,37 @@ class TestMemCache < Test::Unit::TestCase
741
741
  hash = Digest::SHA1.hexdigest(key)
742
742
  @cache.namespace = nil
743
743
  assert_equal key, @cache.make_cache_key(key)
744
+ end
744
745
 
746
+ def test_make_cache_key_with_autofix
745
747
  @cache.autofix_keys = true
746
748
 
747
749
  @cache.namespace = "my_namespace"
748
750
  assert_equal 'my_namespace:key', @cache.make_cache_key('key')
749
751
  @cache.namespace = nil
750
752
  assert_equal 'key', @cache.make_cache_key('key')
751
-
753
+
752
754
  key = "keys with more than two hundred and fifty characters can cause problems, because they get truncated and start colliding with each other. It's not a common occurrence, but when it happens is very hard to debug. the autofix option takes care of that for you"
753
755
  hash = Digest::SHA1.hexdigest(key)
754
756
  @cache.namespace = "my_namespace"
755
757
  assert_equal "my_namespace:#{hash}-autofixed", @cache.make_cache_key(key)
756
758
  @cache.namespace = nil
757
759
  assert_equal "#{hash}-autofixed", @cache.make_cache_key(key)
758
-
760
+
759
761
  key = "a short key with spaces"
760
762
  hash = Digest::SHA1.hexdigest(key)
761
763
  @cache.namespace = "my_namespace"
762
764
  assert_equal "my_namespace:#{hash}-autofixed", @cache.make_cache_key(key)
763
765
  @cache.namespace = nil
764
766
  assert_equal "#{hash}-autofixed", @cache.make_cache_key(key)
767
+
768
+ # namespace + separator + key > 250
769
+ key = 'k' * 240
770
+ hash = Digest::SHA1.hexdigest(key)
771
+ @cache.namespace = 'n' * 10
772
+ assert_equal "#{@cache.namespace}:#{hash}-autofixed", @cache.make_cache_key(key)
765
773
  end
766
-
774
+
767
775
  def test_servers
768
776
  server = FakeServer.new
769
777
  @cache.servers = []
@@ -880,7 +888,7 @@ class TestMemCache < Test::Unit::TestCase
880
888
  @cache.servers << server
881
889
 
882
890
  @cache.prepend 'key', 'value'
883
-
891
+
884
892
  dumped = Marshal.dump('value')
885
893
 
886
894
  expected = "prepend my_namespace:key 0 0 5\r\nvalue\r\n"
@@ -895,7 +903,7 @@ class TestMemCache < Test::Unit::TestCase
895
903
  @cache.servers << server
896
904
 
897
905
  @cache.append 'key', 'value'
898
-
906
+
899
907
  expected = "append my_namespace:key 0 0 5\r\nvalue\r\n"
900
908
  assert_equal expected, server.socket.written.string
901
909
  end
@@ -908,7 +916,7 @@ class TestMemCache < Test::Unit::TestCase
908
916
  @cache.servers << server
909
917
 
910
918
  @cache.replace 'key', 'value', 150
911
-
919
+
912
920
  dumped = Marshal.dump('value')
913
921
 
914
922
  expected = "replace my_namespace:key 0 150 #{dumped.length}\r\n#{dumped}\r\n"
@@ -923,7 +931,7 @@ class TestMemCache < Test::Unit::TestCase
923
931
  @cache.servers << server
924
932
 
925
933
  @cache.add 'key', 'value'
926
-
934
+
927
935
  dumped = Marshal.dump('value')
928
936
 
929
937
  expected = "add my_namespace:key 0 0 #{dumped.length}\r\n#{dumped}\r\n"
@@ -998,10 +1006,10 @@ class TestMemCache < Test::Unit::TestCase
998
1006
  server = FakeServer.new
999
1007
  @cache.servers = []
1000
1008
  @cache.servers << server
1001
-
1009
+
1002
1010
  @cache.delete 'key'
1003
-
1004
- expected = "delete my_namespace:key 0\r\n"
1011
+
1012
+ expected = "delete my_namespace:key\r\n"
1005
1013
  assert_equal expected, server.socket.written.string
1006
1014
  end
1007
1015
 
@@ -1009,10 +1017,10 @@ class TestMemCache < Test::Unit::TestCase
1009
1017
  server = FakeServer.new
1010
1018
  @cache.servers = []
1011
1019
  @cache.servers << server
1012
-
1020
+
1013
1021
  @cache.delete 'key', 300
1014
-
1015
- expected = "delete my_namespace:key 300\r\n"
1022
+
1023
+ expected = "delete my_namespace:key\r\n"
1016
1024
  assert_equal expected, server.socket.written.string
1017
1025
  end
1018
1026
 
@@ -1058,7 +1066,7 @@ class TestMemCache < Test::Unit::TestCase
1058
1066
 
1059
1067
  assert_match(/flush_all\r\n/, socket.written.string)
1060
1068
  end
1061
-
1069
+
1062
1070
  def test_flush_all_for_real
1063
1071
  requirement(memcached_running?, 'A real memcached server must be running for testing flush_all') do
1064
1072
  cache = MemCache.new "localhost:11211", :namespace => "test_flush_all"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsander-memcache-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.7.pre
4
+ version: 1.7.8.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-11-17 00:00:00 +01:00
14
+ date: 2009-12-20 00:00:00 +01:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -66,5 +66,5 @@ signing_key:
66
66
  specification_version: 3
67
67
  summary: A Ruby library for accessing memcached.
68
68
  test_files:
69
- - test/test_benchmark.rb
70
69
  - test/test_mem_cache.rb
70
+ - test/test_benchmark.rb