lru_redux 0.0.6 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/lib/lru_redux/cache19.rb +4 -2
- data/lib/lru_redux/thread_safe_cache.rb +4 -2
- data/lib/lru_redux/version.rb +1 -1
- data/test/cache_test.rb +15 -0
- data/test/thread_safe_cache_test.rb +12 -17
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea015033987bd1895311ed7621db04aaff3ab6b
|
4
|
+
data.tar.gz: 0a9ee0f191f866e5070e381c958b0d12bc1a00bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 615ebf6f43f5b111b63dd136272d84019d5100e889951c458a00b50d901bf07e927614659dbd9e9095967c95b14e4da29d9b840a8a57b7004e4b8b3155f29a4d
|
7
|
+
data.tar.gz: 9be61a373c5c8ff1a212999996b690b14c77a996e469b896362b2164dba4b52f061a69a62c30e94380cf4c6e2887c2fa7fcbe8dc8107cc7f06f71ba012bd0f43
|
data/CHANGELOG
ADDED
data/lib/lru_redux/cache19.rb
CHANGED
@@ -59,7 +59,8 @@ class LruRedux::Cache
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def each
|
62
|
-
@data.
|
62
|
+
array = @data.to_a
|
63
|
+
array.reverse!.each do |pair|
|
63
64
|
yield pair
|
64
65
|
end
|
65
66
|
end
|
@@ -68,7 +69,8 @@ class LruRedux::Cache
|
|
68
69
|
alias_method :each_unsafe, :each
|
69
70
|
|
70
71
|
def to_a
|
71
|
-
@data.to_a
|
72
|
+
array = @data.to_a
|
73
|
+
array.reverse!
|
72
74
|
end
|
73
75
|
|
74
76
|
def delete(k)
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'monitor'
|
3
|
+
|
2
4
|
class LruRedux::ThreadSafeCache < LruRedux::Cache
|
5
|
+
include MonitorMixin
|
3
6
|
def initialize(size)
|
4
|
-
@lock = Mutex.new
|
5
7
|
super(size)
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.synchronize(*methods)
|
9
11
|
methods.each do |method|
|
10
12
|
define_method method do |*args, &blk|
|
11
|
-
|
13
|
+
synchronize do
|
12
14
|
super(*args,&blk)
|
13
15
|
end
|
14
16
|
end
|
data/lib/lru_redux/version.rb
CHANGED
data/test/cache_test.rb
CHANGED
@@ -96,4 +96,19 @@ class CacheTest < MiniTest::Unit::TestCase
|
|
96
96
|
@c.max_size = 1
|
97
97
|
assert_equal [[:c,3]], @c.to_a
|
98
98
|
end
|
99
|
+
|
100
|
+
def test_each
|
101
|
+
@c.max_size = 2
|
102
|
+
@c[:a] = 1
|
103
|
+
@c[:b] = 2
|
104
|
+
@c[:c] = 3
|
105
|
+
|
106
|
+
pairs = []
|
107
|
+
@c.each do |pair|
|
108
|
+
pairs << pair
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_equal [[:c,3],[:b, 2]], pairs
|
112
|
+
|
113
|
+
end
|
99
114
|
end
|
@@ -1,22 +1,17 @@
|
|
1
|
-
require '
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'minitest/pride'
|
1
|
+
require 'cache_test'
|
4
2
|
|
5
|
-
class ThreadSafeCacheTest <
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
4.times do |t|
|
10
|
-
threads << Thread.new do
|
11
|
-
250.times do |i|
|
12
|
-
cache[i] = "#{t} #{i}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
3
|
+
class ThreadSafeCacheTest < CacheTest
|
4
|
+
def setup
|
5
|
+
@c = LruRedux::ThreadSafeCache.new(3)
|
6
|
+
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
def test_recursion
|
9
|
+
@c[:a] = 1
|
10
|
+
@c[:b] = 2
|
20
11
|
|
12
|
+
# should not blow up
|
13
|
+
@c.each do |k,v|
|
14
|
+
@c[k]
|
15
|
+
end
|
21
16
|
end
|
22
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lru_redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ extensions: []
|
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
104
|
- .gitignore
|
105
|
+
- CHANGELOG
|
105
106
|
- Gemfile
|
106
107
|
- Guardfile
|
107
108
|
- LICENSE.txt
|
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
139
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.0.
|
140
|
+
rubygems_version: 2.0.3
|
140
141
|
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: An efficient implementation of an lru cache
|