timshadel-starling 0.9.8.01.20080924 → 0.9.8.01.200809241125

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/starling.rb +44 -7
  2. metadata +1 -1
data/lib/starling.rb CHANGED
@@ -31,14 +31,29 @@ class Starling < MemCache
31
31
  # Starling cluster.
32
32
 
33
33
  def delete(key, expiry = 0)
34
- raise MemCacheError, "Update of readonly cache" if @readonly
35
- cache_key = make_cache_key key
36
-
37
- @buckets.each do |server|
38
- with_socket_management(server) do |socket|
39
- socket.write "delete #{cache_key} #{expiry}\r\n"
40
- socket.gets
34
+ with_servers do
35
+ _original_delete(key, expiry)
36
+ end
37
+ end
38
+
39
+ ##
40
+ # Provides a way to work with a specific list of servers by
41
+ # forcing all calls to #get_server_for_key to use a specific
42
+ # server, and changing that server each time that the call
43
+ # yields to the block provided. This helps work around the
44
+ # normally random nature of the #get_server_for_key method.
45
+ #
46
+ # Acquires the mutex for the entire duration of the call
47
+ # since unrelated calls to #get_server_for_key might be
48
+ # adversely affected by the non_random result.
49
+ def with_servers(my_servers = @servers.dup)
50
+ return unless block_given?
51
+ with_lock do
52
+ my_servers.each do |server|
53
+ @force_server = server
54
+ yield
41
55
  end
56
+ @force_server = nil
42
57
  end
43
58
  end
44
59
 
@@ -117,6 +132,7 @@ class Starling < MemCache
117
132
  raise ArgumentError, "illegal character in key #{key.inspect}" if key =~ /\s/
118
133
  raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
119
134
  raise MemCacheError, "No servers available" if @servers.empty?
135
+ return @force_server if @force_server
120
136
 
121
137
  bukkits = @buckets.dup
122
138
  bukkits.nitems.times do |try|
@@ -129,3 +145,24 @@ class Starling < MemCache
129
145
  raise MemCacheError, "No servers available (all dead)"
130
146
  end
131
147
  end
148
+
149
+
150
+ class MemCache
151
+
152
+ protected
153
+
154
+ ##
155
+ # Ensure that everything within the given block is executed
156
+ # within the locked mutex if this client is multithreaded.
157
+ # If the client isn't multithreaded, the block is simply executed.
158
+ def with_lock
159
+ return unless block_given?
160
+ begin
161
+ @mutex.lock if @multithread
162
+ yield
163
+ ensure
164
+ @mutex.unlock if @multithread
165
+ end
166
+ end
167
+
168
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timshadel-starling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.01.20080924
4
+ version: 0.9.8.01.200809241125
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blaine Cook