mize 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31a2249fb9449c4c378dfaa53ad98e1bdb5e4003
4
- data.tar.gz: ce2086babe68462c54578504fd6d8fe4cec24d2c
3
+ metadata.gz: 4bef89d65104843caaf74b09d5ada0cd6a83e2ef
4
+ data.tar.gz: bd243b61f7745d8b700fbcf5f86b0e6a3869e0f6
5
5
  SHA512:
6
- metadata.gz: 6ea3e5de8e79a5941cf2512776170bb41054bb88db20f9a86cb920b0d534644a423479d3e9a77c681f88cb365fd50ec83171ea4d6285342347e1959e178f7b0a
7
- data.tar.gz: 511cecd51e2655fa03fdeb5868754dd49704f5d44011cf488de8647791c90ed929743da4a466a37c6c789cf4e530eb985e5788c447f60060962cf376e0b7d656
6
+ metadata.gz: d973aff90d3c4b7d1589c44ca1008a3489ddf513e79472f42fe8d83e3eb94064126a2ce76598f249ea327910b3303c8307a1dda399e0b50fde4aec5b1c61cfb2
7
+ data.tar.gz: 361aef55524e499530af71d909a66a36e6fd4c364cb8013d492dbe575eec77be622b5a8fa7baa925f9c816b720078ef8207bfba013708add5eaeddbc99dba37d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -31,5 +31,5 @@ class Mize::DefaultCache < Hash
31
31
 
32
32
  alias prototype dup
33
33
 
34
- # conform_to Mize::CacheProtocol
34
+ conform_to Mize::CacheProtocol
35
35
  end
@@ -1,42 +1,24 @@
1
- require 'monitor'
1
+ require 'thread'
2
2
 
3
3
  module Mize
4
+ MUTEX = Mutex.new
5
+
4
6
  class << self
5
7
 
6
8
  # Clear all memoization caches at once.
7
9
  def cache_clear
8
- each_cache do |id, cache|
9
- cache and cache.clear
10
- cache_tracker.delete id
11
- end
10
+ each_cache(&:clear)
12
11
  end
13
12
 
14
13
  private
15
14
 
16
15
  def each_cache
17
- cache_tracker.synchronize do
18
- cache_tracker.each_name do |id|
19
- begin
20
- cache = ObjectSpace._id2ref id
21
- rescue RangeError
22
- end
23
- Mize::CacheProtocol === cache or cache = nil
24
- yield id, cache
16
+ MUTEX.synchronize do
17
+ for cache in ObjectSpace.each_object(Mize::CacheProtocol)
18
+ yield cache
25
19
  end
26
20
  end
27
- end
28
-
29
- def cache_tracker
30
- @cache_tracker ||= Mize.default_cache.dup
31
- end
32
-
33
- def track_cache(cache_id)
34
- cache_tracker.exist?(cache_id) and return
35
- cache_tracker.synchronize do
36
- cache_tracker.write cache_id, true
37
- end
21
+ self
38
22
  end
39
23
  end
40
-
41
- cache_tracker
42
24
  end
@@ -27,7 +27,7 @@ module Mize
27
27
  def wrap_method(method_id, freeze: false, function: false)
28
28
  include CacheMethods
29
29
 
30
- mc = __mize_cache__
30
+ function and mc = __mize_cache__
31
31
 
32
32
  unless function
33
33
  prepend Mize::Reload
@@ -38,7 +38,6 @@ module Mize
38
38
  orig_method = instance_method(method_id)
39
39
  __send__(:define_method, method_id) do |*args|
40
40
  function or mc = __mize_cache__
41
- Mize.__send__ :track_cache, mc.__id__
42
41
  key = build_key(method_id, *args)
43
42
  if mc.exist?(key) and result = mc.read(key)
44
43
  result
@@ -1,6 +1,6 @@
1
1
  module Mize
2
2
  # Mize version
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mize 0.1.0 ruby lib
2
+ # stub: mize 0.2.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mize"
6
- s.version = "0.1.0"
6
+ s.version = "0.2.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank