lru_redux 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/lru_redux/cache.rb +28 -13
- data/lib/lru_redux/cache19.rb +1 -1
- data/lib/lru_redux/version.rb +1 -1
- data/test/cache_test.rb +10 -1
- metadata +18 -19
- data/CHANGELOG +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db2f5b8b5846daedc0bb154d16890dce33de740
|
4
|
+
data.tar.gz: 054c9c30e079882048d96316d01287dc9fea4ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 158d6276f7699180a9d1044ea68d8c36c5627c916ed28d39809ae661b8c117382cf6d0dbb2a0d9939bbc769bc5e654fa6c0f35d11d04f8942c5355a5ae0dff47
|
7
|
+
data.tar.gz: b718d96261b1bc002dd2d684f7f600c946e087d75598b629b5802528ed564502d04c94b5a5a39c8c9ca47869a5b9b59b245d7b5bbbed74616aef6cb8692f7fdd
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ cache.delete(:a)
|
|
43
43
|
cache.each {|k,v| p "#{k} #{v}"}
|
44
44
|
# b 2
|
45
45
|
|
46
|
-
cache.max_size
|
46
|
+
cache.max_size = 200 # cache now stores 200 items
|
47
47
|
cache.clear # cache has no items
|
48
48
|
|
49
49
|
cache.getset(:a){1}
|
@@ -57,7 +57,7 @@ cache.to_a
|
|
57
57
|
|
58
58
|
# for thread safe access, all methods on cache
|
59
59
|
# are protected with a mutex
|
60
|
-
cache = LruRedux::ThreadSafeCache(100)
|
60
|
+
cache = LruRedux::ThreadSafeCache.new(100)
|
61
61
|
|
62
62
|
```
|
63
63
|
|
@@ -95,6 +95,19 @@ lru_redux thread safe 2.480000 0.000000 2.480000 ( 2.488169)
|
|
95
95
|
|
96
96
|
## Changlog
|
97
97
|
|
98
|
+
###version 0.8.2 - 16-Feb-2014
|
99
|
+
|
100
|
+
- Perf: use #size instead of #count when checking length @Sebrius
|
101
|
+
- Fix: Cache could grow beyond its size in Ruby 1.8 @Sebrius
|
102
|
+
- Fix: #each could deadlock in Ruby 1.8 @Sebrius
|
103
|
+
|
104
|
+
|
105
|
+
###version 0.8.1 - 7-Sep-2013
|
106
|
+
|
107
|
+
- Fix #each implementation
|
108
|
+
- Fix deadlocks with ThreadSafeCache
|
109
|
+
- Version jump is because its been used in production for quite a while now
|
110
|
+
|
98
111
|
###version 0.0.6 - 24-April-2013
|
99
112
|
|
100
113
|
- Fix bug in getset, overflow was not returning the yeilded val
|
data/lib/lru_redux/cache.rb
CHANGED
@@ -28,7 +28,7 @@ class LruRedux::Cache
|
|
28
28
|
move_to_head(node)
|
29
29
|
node[2]
|
30
30
|
else
|
31
|
-
|
31
|
+
self[key] = yield
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -38,7 +38,7 @@ class LruRedux::Cache
|
|
38
38
|
move_to_head(node)
|
39
39
|
node[2]
|
40
40
|
else
|
41
|
-
|
41
|
+
yield if block_given?
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -63,7 +63,15 @@ class LruRedux::Cache
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def each
|
66
|
-
|
66
|
+
a = to_a
|
67
|
+
a.each do |pair|
|
68
|
+
yield pair
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each_unsafe
|
73
|
+
n = @head
|
74
|
+
if n
|
67
75
|
while n
|
68
76
|
yield [n[1], n[2]]
|
69
77
|
n = n[0]
|
@@ -71,9 +79,6 @@ class LruRedux::Cache
|
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
74
|
-
# used further up the chain, non thread safe each
|
75
|
-
alias_method :each_unsafe, :each
|
76
|
-
|
77
82
|
def to_a
|
78
83
|
a = []
|
79
84
|
self.each_unsafe do |k,v|
|
@@ -82,8 +87,21 @@ class LruRedux::Cache
|
|
82
87
|
a
|
83
88
|
end
|
84
89
|
|
85
|
-
def delete(
|
86
|
-
|
90
|
+
def delete(key)
|
91
|
+
node = @data.delete(key)
|
92
|
+
return unless node
|
93
|
+
|
94
|
+
if node[3].nil?
|
95
|
+
@head = @head[0]
|
96
|
+
if @head.nil?
|
97
|
+
@tail = nil
|
98
|
+
else
|
99
|
+
@head[3] = nil
|
100
|
+
end
|
101
|
+
elsif node[0].nil?
|
102
|
+
@tail = @tail[3]
|
103
|
+
@tail[0] = nil
|
104
|
+
else
|
87
105
|
prev = node[0]
|
88
106
|
nex = node[3]
|
89
107
|
|
@@ -98,19 +116,17 @@ class LruRedux::Cache
|
|
98
116
|
end
|
99
117
|
|
100
118
|
def count
|
101
|
-
@data.
|
119
|
+
@data.size
|
102
120
|
end
|
103
121
|
|
104
122
|
# for cache validation only, ensures all is sound
|
105
123
|
def valid?
|
106
|
-
expected = {}
|
107
|
-
|
108
124
|
count = 0
|
109
125
|
self.each_unsafe do |k,v|
|
110
126
|
return false if @data[k][2] != v
|
111
127
|
count += 1
|
112
128
|
end
|
113
|
-
count == @data.
|
129
|
+
count == @data.size
|
114
130
|
end
|
115
131
|
|
116
132
|
protected
|
@@ -153,5 +169,4 @@ class LruRedux::Cache
|
|
153
169
|
true
|
154
170
|
end
|
155
171
|
end
|
156
|
-
|
157
172
|
end
|
data/lib/lru_redux/cache19.rb
CHANGED
data/lib/lru_redux/version.rb
CHANGED
data/test/cache_test.rb
CHANGED
@@ -57,9 +57,18 @@ class CacheTest < MiniTest::Unit::TestCase
|
|
57
57
|
@c[:a] = 1
|
58
58
|
@c[:b] = 2
|
59
59
|
@c[:c] = 3
|
60
|
+
@c.delete(:a)
|
60
61
|
|
62
|
+
assert_equal [[:c,3],[:b,2]], @c.to_a
|
63
|
+
assert_nil @c[:a]
|
64
|
+
|
65
|
+
# Regression test for a bug in the legacy delete method
|
61
66
|
@c.delete(:b)
|
62
|
-
|
67
|
+
@c[:d] = 4
|
68
|
+
@c[:e] = 5
|
69
|
+
@c[:f] = 6
|
70
|
+
|
71
|
+
assert_equal [[:f,6],[:e,5],[:d,4]], @c.to_a
|
63
72
|
assert_nil @c[:b]
|
64
73
|
end
|
65
74
|
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lru_redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard-minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rb-inotify
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: An efficient implementation of an lru cache
|
@@ -101,8 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
105
|
-
- CHANGELOG
|
104
|
+
- ".gitignore"
|
106
105
|
- Gemfile
|
107
106
|
- Guardfile
|
108
107
|
- LICENSE.txt
|
@@ -127,17 +126,17 @@ require_paths:
|
|
127
126
|
- lib
|
128
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
128
|
requirements:
|
130
|
-
- -
|
129
|
+
- - ">="
|
131
130
|
- !ruby/object:Gem::Version
|
132
131
|
version: '0'
|
133
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
133
|
requirements:
|
135
|
-
- -
|
134
|
+
- - ">="
|
136
135
|
- !ruby/object:Gem::Version
|
137
136
|
version: '0'
|
138
137
|
requirements: []
|
139
138
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.2.2
|
141
140
|
signing_key:
|
142
141
|
specification_version: 4
|
143
142
|
summary: An efficient implementation of an lru cache
|