lru_redux 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -12
- data/bench/bench.rb +16 -7
- data/lib/lru_redux/thread_safe_cache.rb +64 -11
- data/lib/lru_redux/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cc0a735826e07e6de5cc53e431c4fd87ff32413
|
4
|
+
data.tar.gz: 28446a234e46a8b91a57e56b1677b2d4b16ac68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc3d02a4d7b2f4f3db8189e1e4c5c1515c2e3c713d58ce2e84ba46296aec74312400c11e60f31cebfc8fd757210c347c5beb0ea13375501164a847a12326bebb
|
7
|
+
data.tar.gz: 4c46517993f671162baa8aa946ad201d8ce00f662b1b61f8583463041752f73da2ee57ff802e130448ae427cc12064a32eb4d4e815d3ed96e941e7d2db69593b
|
data/README.md
CHANGED
@@ -66,21 +66,21 @@ cache = LruRedux::ThreadSafeCache.new(100)
|
|
66
66
|
see: benchmark directory (a million random lookup / store)
|
67
67
|
|
68
68
|
```
|
69
|
-
|
69
|
+
$ ruby ./bench/bench.rb
|
70
70
|
Rehearsal ---------------------------------------------------------
|
71
|
-
thread safe lru
|
72
|
-
lru gem 2.
|
73
|
-
lru_cache gem 1.
|
74
|
-
lru_redux gem 1.
|
75
|
-
lru_redux thread safe 2.
|
76
|
-
----------------------------------------------- total:
|
71
|
+
thread safe lru 4.530000 0.020000 4.550000 ( 4.540861)
|
72
|
+
lru gem 2.040000 0.000000 2.040000 ( 2.046777)
|
73
|
+
lru_cache gem 1.660000 0.010000 1.670000 ( 1.670404)
|
74
|
+
lru_redux gem 1.200000 0.000000 1.200000 ( 1.197036)
|
75
|
+
lru_redux thread safe 2.520000 0.000000 2.520000 ( 2.526945)
|
76
|
+
----------------------------------------------- total: 11.980000sec
|
77
77
|
|
78
78
|
user system total real
|
79
|
-
thread safe lru
|
80
|
-
lru gem 2.
|
81
|
-
lru_cache gem 1.
|
82
|
-
lru_redux gem 1.
|
83
|
-
lru_redux thread safe 2.
|
79
|
+
thread safe lru 4.550000 0.030000 4.580000 ( 4.581848)
|
80
|
+
lru gem 2.060000 0.000000 2.060000 ( 2.056636)
|
81
|
+
lru_cache gem 1.660000 0.010000 1.670000 ( 1.669312)
|
82
|
+
lru_redux gem 1.180000 0.000000 1.180000 ( 1.187639)
|
83
|
+
lru_redux thread safe 2.530000 0.000000 2.530000 ( 2.532061)
|
84
84
|
|
85
85
|
```
|
86
86
|
|
@@ -95,6 +95,10 @@ lru_redux thread safe 2.480000 0.000000 2.480000 ( 2.488169)
|
|
95
95
|
|
96
96
|
## Changlog
|
97
97
|
|
98
|
+
###version 0.8.3 - 20-Feb-2014
|
99
|
+
|
100
|
+
- Perf: improve ThreadSafeCache performance @Sevrius
|
101
|
+
|
98
102
|
###version 0.8.2 - 16-Feb-2014
|
99
103
|
|
100
104
|
- Perf: use #size instead of #count when checking length @Sebrius
|
data/bench/bench.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'lru'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'lru_cache'
|
5
|
+
require 'threadsafe-lru'
|
6
6
|
$LOAD_PATH.unshift File.expand_path '../lib'
|
7
7
|
require File.expand_path('../../lib/lru_redux', __FILE__)
|
8
8
|
|
@@ -24,8 +24,6 @@ bm = Benchmark.bmbm do |bm|
|
|
24
24
|
[
|
25
25
|
[lru, "lru gem"],
|
26
26
|
[lru_cache, "lru_cache gem"],
|
27
|
-
[lru_redux, "lru_redux gem"],
|
28
|
-
[lru_redux_thread_safe, "lru_redux thread safe"]
|
29
27
|
].each do |cache, name|
|
30
28
|
bm.report name do
|
31
29
|
1_000_000.times do
|
@@ -33,4 +31,15 @@ bm = Benchmark.bmbm do |bm|
|
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
34
|
+
|
35
|
+
[
|
36
|
+
[lru_redux, "lru_redux gem"],
|
37
|
+
[lru_redux_thread_safe, "lru_redux thread safe"]
|
38
|
+
].each do |cache, name|
|
39
|
+
bm.report name do
|
40
|
+
1_000_000.times do
|
41
|
+
cache.getset(rand(2_000)) { :value }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
36
45
|
end
|
@@ -1,22 +1,75 @@
|
|
1
|
-
require 'thread'
|
2
1
|
require 'monitor'
|
3
2
|
|
4
3
|
class LruRedux::ThreadSafeCache < LruRedux::Cache
|
5
4
|
include MonitorMixin
|
6
|
-
|
7
|
-
|
5
|
+
|
6
|
+
def initialize(max_size)
|
7
|
+
super(max_size)
|
8
|
+
end
|
9
|
+
|
10
|
+
def max_size=(size)
|
11
|
+
synchronize do
|
12
|
+
super(size)
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
synchronize do
|
14
|
-
super(*args,&blk)
|
15
|
-
end
|
16
|
-
end
|
16
|
+
def getset(key)
|
17
|
+
synchronize do
|
18
|
+
super(key)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
22
|
+
def fetch(key)
|
23
|
+
synchronize do
|
24
|
+
super(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
synchronize do
|
30
|
+
super(key)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def []=(key, value)
|
35
|
+
synchronize do
|
36
|
+
super(key, value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def each
|
41
|
+
synchronize do
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
21
45
|
|
46
|
+
def to_a
|
47
|
+
synchronize do
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete(key)
|
53
|
+
synchronize do
|
54
|
+
super(key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def clear
|
59
|
+
synchronize do
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def count
|
65
|
+
synchronize do
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def valid?
|
71
|
+
synchronize do
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
22
75
|
end
|
data/lib/lru_redux/version.rb
CHANGED
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.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|