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 +4 -4
- data/VERSION +1 -1
- data/lib/mize/default_cache.rb +1 -1
- data/lib/mize/global_clear.rb +8 -26
- data/lib/mize/memoize.rb +1 -2
- data/lib/mize/version.rb +1 -1
- data/mize.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bef89d65104843caaf74b09d5ada0cd6a83e2ef
|
4
|
+
data.tar.gz: bd243b61f7745d8b700fbcf5f86b0e6a3869e0f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d973aff90d3c4b7d1589c44ca1008a3489ddf513e79472f42fe8d83e3eb94064126a2ce76598f249ea327910b3303c8307a1dda399e0b50fde4aec5b1c61cfb2
|
7
|
+
data.tar.gz: 361aef55524e499530af71d909a66a36e6fd4c364cb8013d492dbe575eec77be622b5a8fa7baa925f9c816b720078ef8207bfba013708add5eaeddbc99dba37d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/mize/default_cache.rb
CHANGED
data/lib/mize/global_clear.rb
CHANGED
@@ -1,42 +1,24 @@
|
|
1
|
-
require '
|
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
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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
|
data/lib/mize/memoize.rb
CHANGED
@@ -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
|
data/lib/mize/version.rb
CHANGED
data/mize.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mize 0.
|
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.
|
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"]
|