cache_method 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 0.2.5 / 2012-04-24
2
+
3
+ * Enhancements
4
+
5
+ * If you immediately obtain the fetch mutex, don't double-get because for all you know you're the first setter
6
+ * Better debug logging (require 'cache_method/debug')
7
+
1
8
  0.2.4 / 2012-04-17
2
9
 
3
10
  * Enhancements
@@ -26,8 +26,18 @@ module CacheMethod
26
26
  if wrapped_v = get_wrapped
27
27
  wrapped_v.first
28
28
  else
29
- @fetch_mutex.synchronize do
30
- (get_wrapped || set_wrapped).first
29
+ if @fetch_mutex.try_lock
30
+ # i got the lock, so don't bother trying to get first
31
+ begin
32
+ set_wrapped.first
33
+ ensure
34
+ @fetch_mutex.unlock
35
+ end
36
+ else
37
+ # i didn't get the lock, so get in line, and do try to get first
38
+ @fetch_mutex.synchronize do
39
+ (get_wrapped || set_wrapped).first
40
+ end
31
41
  end
32
42
  end
33
43
  end
@@ -1,8 +1,34 @@
1
1
  module CacheMethod
2
2
  def CacheMethod.digest(obj)
3
3
  if (l = ::Marshal.dump(resolve_cache_key(obj)).length) > 500
4
- $stderr.puts "[cache_method] Warn: #{l} long digest. #{obj.class} -> #{resolve_cache_key(obj).inspect}"
4
+ $stderr.puts "[cache_method] DIGEST (long?): #{resolve_cache_key(obj).inspect}"
5
5
  end
6
6
  ::Digest::SHA1.hexdigest ::Marshal.dump(resolve_cache_key(obj))
7
7
  end
8
+
9
+ class CachedResult
10
+ def debug_get_wrapped
11
+ retval = original_get_wrapped
12
+ if retval
13
+ # $stderr.puts "[cache_method] GET: #{method_signature}(#{args.inspect})"
14
+ else
15
+ $stderr.puts "[cache_method] GET (miss!): #{method_signature}(#{args.inspect})"
16
+ end
17
+ retval
18
+ end
19
+ alias :original_get_wrapped :get_wrapped
20
+ alias :get_wrapped :debug_get_wrapped
21
+
22
+ def debug_set_wrapped
23
+ retval = original_set_wrapped
24
+ if (l = ::Marshal.dump(retval).length > 1000)
25
+ $stderr.puts "[cache_method] SET (long?): #{method_signature}(#{args.inspect}) -> #{retval.inspect}"
26
+ else
27
+ # $stderr.puts "[cache_method] SET: #{method_signature}(#{args.inspect})"
28
+ end
29
+ retval
30
+ end
31
+ alias :original_set_wrapped :set_wrapped
32
+ alias :set_wrapped :debug_set_wrapped
33
+ end
8
34
  end
@@ -1,3 +1,3 @@
1
1
  module CacheMethod
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-17 00:00:00.000000000 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cache