sin_lru_redux 2.2.1 → 2.3.0
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/CHANGELOG.md +7 -0
- data/README.md +4 -1
- data/lib/lru_redux/cache.rb +21 -19
- data/lib/lru_redux/ttl/cache.rb +2 -0
- data/lib/lru_redux/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a205e8ba667a41a33f3b7fdb9d86e6ab3cc5623aff0998a31e00899db3069535
|
4
|
+
data.tar.gz: 6b3cad6832644bdc3c8ec26e821f7ff855f1591c99be6a127ba55b048943f1e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63f527c1469a8cc98b48be9c9248bd6406d75db63443930368e328106048d4aafaba3f9f560d63ab4e535c832d9485b90e69039c5b496999fd91535411116a1e
|
7
|
+
data.tar.gz: f10d3bb3ec140660b562f8246eaa89acf1bbe6b497b5d283d5494b4ac57cce1621ab932fc4f55cc70dc995fd933ba12fa71d72311683e31c93a2bd37d184fe4b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ cache[:a] # a pushed to front
|
|
49
49
|
cache.to_a
|
50
50
|
# [[:a, '1'], [:b, '2']]
|
51
51
|
cache.delete(:a)
|
52
|
-
cache.each { |
|
52
|
+
cache.each { |key, value| puts "#{key} #{value}"}
|
53
53
|
# b 2
|
54
54
|
|
55
55
|
cache.max_size = 200 # cache now stores 200 items
|
@@ -145,10 +145,13 @@ cache = LruRedux::TTL::ThreadSafeCache.new(100, 5 * 60)
|
|
145
145
|
- `#evict` Alias for `#delete`.
|
146
146
|
- `#clear` Clears the cache. Returns nil.
|
147
147
|
- `#each` Takes a block. Executes the block on each key-value pair in LRU order (most recent first).
|
148
|
+
- `#each_unsafe` Alias for `#each`.
|
148
149
|
- `#to_a` Return an array of key-value pairs (arrays) in LRU order (most recent first).
|
149
150
|
- `#key?` Takes a key. Returns true if the key is cached, otherwise false.
|
150
151
|
- `#has_key?` Alias for `#key?`.
|
151
152
|
- `#count` Return the current number of items stored in the cache.
|
153
|
+
- `#length` Alias for `#count`.
|
154
|
+
- `#size` Alias for `#count`.
|
152
155
|
- `#max_size` Returns the current maximum size of the cache.
|
153
156
|
- `#max_size=` Takes a positive number. Changes the current max_size and triggers a resize. Also triggers TTL eviction on the TTL cache.
|
154
157
|
- `#ignore_nil` Returns the current ignore nil setting.
|
data/lib/lru_redux/cache.rb
CHANGED
@@ -14,7 +14,7 @@ class LruRedux::Cache
|
|
14
14
|
|
15
15
|
@max_size = max_size
|
16
16
|
@ignore_nil = ignore_nil
|
17
|
-
@
|
17
|
+
@data_lru = {}
|
18
18
|
end
|
19
19
|
|
20
20
|
def max_size=(new_max_size)
|
@@ -37,10 +37,10 @@ class LruRedux::Cache
|
|
37
37
|
|
38
38
|
def getset(key)
|
39
39
|
key_found = true
|
40
|
-
value = @
|
40
|
+
value = @data_lru.delete(key) { key_found = false }
|
41
41
|
|
42
42
|
if key_found
|
43
|
-
@
|
43
|
+
@data_lru[key] = value
|
44
44
|
else
|
45
45
|
result = yield
|
46
46
|
store_item(key, result)
|
@@ -50,10 +50,10 @@ class LruRedux::Cache
|
|
50
50
|
|
51
51
|
def fetch(key)
|
52
52
|
key_found = true
|
53
|
-
value = @
|
53
|
+
value = @data_lru.delete(key) { key_found = false }
|
54
54
|
|
55
55
|
if key_found
|
56
|
-
@
|
56
|
+
@data_lru[key] = value
|
57
57
|
else
|
58
58
|
yield if block_given? # rubocop:disable Style/IfInsideElse
|
59
59
|
end
|
@@ -61,10 +61,10 @@ class LruRedux::Cache
|
|
61
61
|
|
62
62
|
def [](key)
|
63
63
|
key_found = true
|
64
|
-
value = @
|
64
|
+
value = @data_lru.delete(key) { key_found = false }
|
65
65
|
return unless key_found
|
66
66
|
|
67
|
-
@
|
67
|
+
@data_lru[key] = value
|
68
68
|
end
|
69
69
|
|
70
70
|
def []=(key, val)
|
@@ -72,36 +72,38 @@ class LruRedux::Cache
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def each(&block)
|
75
|
-
@
|
75
|
+
@data_lru.to_a.reverse_each(&block)
|
76
76
|
end
|
77
77
|
# Used further up the chain, non thread safe each
|
78
78
|
alias_method :each_unsafe, :each
|
79
79
|
|
80
80
|
def to_a
|
81
|
-
@
|
81
|
+
@data_lru.to_a.reverse
|
82
82
|
end
|
83
83
|
|
84
84
|
def values
|
85
|
-
@
|
85
|
+
@data_lru.values.reverse
|
86
86
|
end
|
87
87
|
|
88
88
|
def delete(key)
|
89
|
-
@
|
89
|
+
@data_lru.delete(key)
|
90
90
|
end
|
91
91
|
alias_method :evict, :delete
|
92
92
|
|
93
93
|
def key?(key)
|
94
|
-
@
|
94
|
+
@data_lru.key?(key)
|
95
95
|
end
|
96
96
|
alias_method :has_key?, :key?
|
97
97
|
|
98
98
|
def clear
|
99
|
-
@
|
99
|
+
@data_lru.clear
|
100
100
|
end
|
101
101
|
|
102
102
|
def count
|
103
|
-
@
|
103
|
+
@data_lru.size
|
104
104
|
end
|
105
|
+
alias_method :length, :count
|
106
|
+
alias_method :size, :count
|
105
107
|
|
106
108
|
private
|
107
109
|
|
@@ -135,26 +137,26 @@ class LruRedux::Cache
|
|
135
137
|
end
|
136
138
|
|
137
139
|
def evict_excess
|
138
|
-
@
|
140
|
+
@data_lru.shift while @data_lru.size > @max_size
|
139
141
|
end
|
140
142
|
|
141
143
|
if RUBY_VERSION >= '2.6.0'
|
142
144
|
def evict_nil
|
143
145
|
return unless @ignore_nil
|
144
146
|
|
145
|
-
@
|
147
|
+
@data_lru.compact!
|
146
148
|
end
|
147
149
|
else
|
148
150
|
def evict_nil
|
149
151
|
return unless @ignore_nil
|
150
152
|
|
151
|
-
@
|
153
|
+
@data_lru.reject! { |_key, value| value.nil? }
|
152
154
|
end
|
153
155
|
end
|
154
156
|
|
155
157
|
def store_item(key, val)
|
156
|
-
@
|
157
|
-
@
|
158
|
+
@data_lru.delete(key)
|
159
|
+
@data_lru[key] = val if !val.nil? || !@ignore_nil
|
158
160
|
evict_excess
|
159
161
|
val
|
160
162
|
end
|
data/lib/lru_redux/ttl/cache.rb
CHANGED
data/lib/lru_redux/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sin_lru_redux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-01-01 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: |
|
13
13
|
Efficient and thread-safe LRU cache.
|
@@ -33,15 +33,15 @@ files:
|
|
33
33
|
- lib/lru_redux/util.rb
|
34
34
|
- lib/lru_redux/util/safe_sync.rb
|
35
35
|
- lib/lru_redux/version.rb
|
36
|
-
homepage: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.
|
36
|
+
homepage: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.3.0
|
37
37
|
licenses:
|
38
38
|
- MIT
|
39
39
|
metadata:
|
40
|
-
homepage_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.
|
41
|
-
source_code_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.
|
42
|
-
changelog_uri: https://github.com/cadenza-tech/sin_lru_redux/blob/v2.
|
40
|
+
homepage_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.3.0
|
41
|
+
source_code_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.3.0
|
42
|
+
changelog_uri: https://github.com/cadenza-tech/sin_lru_redux/blob/v2.3.0/CHANGELOG.md
|
43
43
|
bug_tracker_uri: https://github.com/cadenza-tech/sin_lru_redux/issues
|
44
|
-
documentation_uri: https://rubydoc.info/gems/sin_lru_redux/2.
|
44
|
+
documentation_uri: https://rubydoc.info/gems/sin_lru_redux/2.3.0
|
45
45
|
rubygems_mfa_required: 'true'
|
46
46
|
rdoc_options: []
|
47
47
|
require_paths:
|