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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b501fa162a36c12d13ff683ccbaa0e85ddda003d
4
- data.tar.gz: 2888a33f2c15f078bec636d3782b8de0cb61f519
3
+ metadata.gz: 3ea015033987bd1895311ed7621db04aaff3ab6b
4
+ data.tar.gz: 0a9ee0f191f866e5070e381c958b0d12bc1a00bb
5
5
  SHA512:
6
- metadata.gz: 5290cdf6e1b0a5014154891464790005625451db37c7959217da68b6f1f6a3ad41d46370bdcb734ed098cda4cb3945a12ea805284898c213c581a9f9b913d83c
7
- data.tar.gz: 7b1cf05f55aa7f314ef9b4b346dca6d7ca20bf5458e893c4a32d4ae1fcb225a3bc6f2992cd1aee54e944f5e03e77cfeacecde69e46b711b272ebb1fe2648c0cd
6
+ metadata.gz: 615ebf6f43f5b111b63dd136272d84019d5100e889951c458a00b50d901bf07e927614659dbd9e9095967c95b14e4da29d9b840a8a57b7004e4b8b3155f29a4d
7
+ data.tar.gz: 9be61a373c5c8ff1a212999996b690b14c77a996e469b896362b2164dba4b52f061a69a62c30e94380cf4c6e2887c2fa7fcbe8dc8107cc7f06f71ba012bd0f43
@@ -0,0 +1,5 @@
1
+ 7-Sep-2013
2
+
3
+ * fix #each implementation
4
+ * fix deadlocks with ThreadSafeCache
5
+ * version 0.8.1 ( its been used in prd for quite a while now )
@@ -59,7 +59,8 @@ class LruRedux::Cache
59
59
  end
60
60
 
61
61
  def each
62
- @data.reverse.each do |pair|
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.reverse
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
- @lock.synchronize do
13
+ synchronize do
12
14
  super(*args,&blk)
13
15
  end
14
16
  end
@@ -1,3 +1,3 @@
1
1
  module LruRedux
2
- VERSION = "0.0.6"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -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 'lru_redux'
2
- require 'minitest/autorun'
3
- require 'minitest/pride'
1
+ require 'cache_test'
4
2
 
5
- class ThreadSafeCacheTest < MiniTest::Unit::TestCase
6
- def test_additions
7
- cache = LruRedux::ThreadSafeCache.new(1000)
8
- threads = []
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
- threads.each{|t| t.join}
18
- assert_equal cache.count,250
19
- assert true, cache.valid?
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.0.6
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-04-23 00:00:00.000000000 Z
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.0.rc.2
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