memcache-client 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ = 1.2.1
2
+
3
+ * Fix bug #7048, MemCache#servers= referenced changed local variable.
4
+ Submitted by Justin Dossey.
5
+ * Fix bug #7049, MemCache#initialize resets @buckets. Submitted by
6
+ Justin Dossey.
7
+ * Fix bug #6232, Make Cache::Get work with a block only when nil is
8
+ returned. Submitted by Jon Evans.
9
+ * Moved to the seattlerb project.
10
+
1
11
  = 1.2.0
2
12
 
3
13
  NOTE: This version will store keys in different places than previous
data/Rakefile CHANGED
@@ -2,16 +2,20 @@
2
2
 
3
3
  require 'hoe'
4
4
 
5
+ require './lib/memcache'
6
+
5
7
  DEV_DOC_PATH = "Libraries/memcache-client"
6
8
 
7
- hoe = Hoe.new 'memcache-client', '1.2.0' do |p|
9
+ hoe = Hoe.new 'memcache-client', MemCache::VERSION do |p|
8
10
  p.summary = 'A Ruby memcached client'
9
11
  p.description = 'memcache-client is a pure-ruby client to Danga\'s memcached.'
10
12
  p.author = ['Eric Hodel', 'Robert Cottrell']
11
13
  p.email = 'eric@robotcoop.com'
12
14
  p.url = "http://dev.robotcoop.com/#{DEV_DOC_PATH}"
15
+ p.changes = File.read('History.txt').scan(/\A(=.*?)^=/m).first.first
13
16
 
14
- p.rubyforge_name = 'rctools'
17
+ p.rubyforge_name = 'seattlerb'
18
+ p.extra_deps << ['ZenTest', '>= 3.4.2']
15
19
  end
16
20
 
17
21
  SPEC = hoe.spec
data/lib/memcache.rb CHANGED
@@ -38,6 +38,11 @@ end
38
38
 
39
39
  class MemCache
40
40
 
41
+ ##
42
+ # The version of MemCache you are using.
43
+
44
+ VERSION = '1.2.1'
45
+
41
46
  ##
42
47
  # Default options for the cache object.
43
48
 
@@ -109,8 +114,8 @@ class MemCache
109
114
  @readonly = opts[:readonly]
110
115
  @multithread = opts[:multithread]
111
116
  @mutex = Mutex.new if @multithread
112
- self.servers = servers
113
117
  @buckets = []
118
+ self.servers = servers
114
119
  end
115
120
 
116
121
  ##
@@ -155,8 +160,7 @@ class MemCache
155
160
  end
156
161
  server
157
162
  else
158
- raise TypeError, "Cannot convert %s to MemCache::Server" %
159
- svr.class.name
163
+ raise TypeError, "cannot convert #{server.class} into MemCache::Server"
160
164
  end
161
165
  end
162
166
 
data/lib/memcache_util.rb CHANGED
@@ -4,68 +4,61 @@
4
4
 
5
5
  module Cache
6
6
 
7
- ##
8
- # Returns the object at +key+ from the cache if successful, or nil if
9
- # either the object is not in the cache or if there was an error
10
- # attermpting to access the cache.
11
- #
12
- # If there is a cache miss and a block is given the result of the block
13
- # will be stored in the cache with optional +expiry+.
7
+ ##
8
+ # Returns the object at +key+ from the cache if successful, or nil if either
9
+ # the object is not in the cache or if there was an error attermpting to
10
+ # access the cache.
11
+ #
12
+ # If there is a cache miss and a block is given the result of the block will
13
+ # be stored in the cache with optional +expiry+.
14
14
 
15
- def self.get(key, expiry = 0)
16
- start_time = Time.now
17
- result = CACHE.get key
18
- end_time = Time.now
19
- ActiveRecord::Base.logger.debug('MemCache Get (%0.6f) %s' %
20
- [end_time - start_time, key])
21
- return result
22
- rescue MemCache::MemCacheError => err
23
- ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
24
- if block_given? then
25
- value = yield
26
- put key, value, expiry
27
- return value
28
- else
29
- return nil
30
- end
15
+ def self.get(key, expiry = 0)
16
+ start_time = Time.now
17
+ result = CACHE.get key
18
+ elapsed = Time.now - start_time
19
+ ActiveRecord::Base.logger.debug('MemCache Get (%0.6f) %s' % [elapsed, key])
20
+ if result.nil? and block_given? then
21
+ value = yield
22
+ put key, value, expiry
31
23
  end
24
+ return result
25
+ rescue MemCache::MemCacheError => err
26
+ ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
27
+ end
32
28
 
33
- ##
34
- # Places +value+ in the cache at +key+, with an optional +expiry+ time in
35
- # seconds.
29
+ ##
30
+ # Places +value+ in the cache at +key+, with an optional +expiry+ time in
31
+ # seconds.
36
32
 
37
- def self.put(key, value, expiry = 0)
38
- start_time = Time.now
39
- CACHE.set key, value, expiry
40
- end_time = Time.now
41
- ActiveRecord::Base.logger.debug('MemCache Set (%0.6f) %s' %
42
- [end_time - start_time, key])
43
- rescue MemCache::MemCacheError => err
44
- ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
45
- end
33
+ def self.put(key, value, expiry = 0)
34
+ start_time = Time.now
35
+ CACHE.set key, value, expiry
36
+ elapsed = Time.now - start_time
37
+ ActiveRecord::Base.logger.debug('MemCache Set (%0.6f) %s' % [elapsed, key])
38
+ rescue MemCache::MemCacheError => err
39
+ ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
40
+ end
46
41
 
47
- ##
48
- # Deletes +key+ from the cache in +delay+ seconds. (?)
42
+ ##
43
+ # Deletes +key+ from the cache in +delay+ seconds.
49
44
 
50
- def self.delete(key, delay = nil)
51
- start_time = Time.now
52
- CACHE.delete key, delay
53
- end_time = Time.now
54
- ActiveRecord::Base.logger.debug('MemCache Delete (%0.6f) %s' %
55
- [end_time - start_time, key])
56
- rescue MemCache::MemCacheError => err
57
- ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
58
- end
45
+ def self.delete(key, delay = nil)
46
+ start_time = Time.now
47
+ CACHE.delete key, delay
48
+ elapsed = Time.now - start_time
49
+ ActiveRecord::Base.logger.debug('MemCache Delete (%0.6f) %s' %
50
+ [elapsed, key])
51
+ rescue MemCache::MemCacheError => err
52
+ ActiveRecord::Base.logger.debug "MemCache Error: #{err.message}"
53
+ end
59
54
 
60
- ##
61
- # Resets all connections to mecache servers.
55
+ ##
56
+ # Resets all connections to MemCache servers.
62
57
 
63
- def self.reset
64
- CACHE.reset
65
- ActiveRecord::Base.logger.debug 'MemCache Connections Reset'
66
- end
67
-
68
- end
58
+ def self.reset
59
+ CACHE.reset
60
+ ActiveRecord::Base.logger.debug 'MemCache Connections Reset'
61
+ end
69
62
 
70
- # vim: ts=4 sts=4 sw=4
63
+ end
71
64
 
@@ -1,5 +1,7 @@
1
1
  require 'stringio'
2
2
  require 'test/unit'
3
+ require 'rubygems'
4
+ require 'test/zentest_assertions'
3
5
 
4
6
  $TESTING = true
5
7
 
@@ -122,6 +124,16 @@ class TestMemCache < Test::Unit::TestCase
122
124
  assert_equal 'first argument must be Array, Hash or String', e.message
123
125
  end
124
126
 
127
+ def test_initialize_multiple_servers
128
+ cache = MemCache.new %w[localhost:11211 localhost:11212],
129
+ :namespace => 'my_namespace', :readonly => true
130
+
131
+ assert_equal 'my_namespace', cache.namespace
132
+ assert_equal true, cache.readonly?
133
+ assert_equal false, cache.servers.empty?
134
+ deny_empty cache.instance_variable_get(:@buckets)
135
+ end
136
+
125
137
  def test_initialize_too_many_args
126
138
  assert_raises ArgumentError do
127
139
  MemCache.new 1, 2, 3
@@ -233,6 +245,14 @@ class TestMemCache < Test::Unit::TestCase
233
245
  assert_equal 'key', @cache.make_cache_key('key')
234
246
  end
235
247
 
248
+ def test_servers_equals_type_error
249
+ e = assert_raise TypeError do
250
+ @cache.servers = [Object.new]
251
+ end
252
+
253
+ assert_equal 'cannot convert Object into MemCache::Server', e.message
254
+ end
255
+
236
256
  def test_basic_threaded_operations_should_work
237
257
  cache = MemCache.new :multithread => true,
238
258
  :namespace => 'my_namespace',
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.99
2
+ rubygems_version: 0.9.0.7
3
3
  specification_version: 1
4
4
  name: memcache-client
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.0
7
- date: 2006-10-17 00:00:00 -07:00
6
+ version: 1.2.1
7
+ date: 2006-12-06 00:00:00 -08:00
8
8
  summary: A Ruby memcached client
9
9
  require_paths:
10
10
  - lib
11
- - test
12
11
  email: eric@robotcoop.com
13
12
  homepage: http://dev.robotcoop.com/Libraries/memcache-client
14
- rubyforge_project: rctools
13
+ rubyforge_project: seattlerb
15
14
  description: memcache-client is a pure-ruby client to Danga's memcached.
16
15
  autorequire:
17
16
  default_executable:
@@ -39,8 +38,8 @@ files:
39
38
  - lib/memcache.rb
40
39
  - lib/memcache_util.rb
41
40
  - test/test_mem_cache.rb
42
- test_files: []
43
-
41
+ test_files:
42
+ - test/test_mem_cache.rb
44
43
  rdoc_options: []
45
44
 
46
45
  extra_rdoc_files: []
@@ -59,5 +58,14 @@ dependencies:
59
58
  requirements:
60
59
  - - ">="
61
60
  - !ruby/object:Gem::Version
62
- version: 1.1.0
61
+ version: 1.1.5
62
+ version:
63
+ - !ruby/object:Gem::Dependency
64
+ name: ZenTest
65
+ version_requirement:
66
+ version_requirements: !ruby/object:Gem::Version::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.4.2
63
71
  version: