sin_lru_redux 2.1.0 → 2.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10d8a07bc1dcf5957a24804163d1ac62086dac85b3cefce3ff305757231a3696
4
- data.tar.gz: 4820d035651c937d4486800a4ca3b1fda48ccfb1118d0bcd420bf49b88c5583e
3
+ metadata.gz: 62aedb1e0b7730269fe2f336ae70bdfd158cf38efd0827c8fae3bd4810e4b0dc
4
+ data.tar.gz: db0572e99799e265c3d6b8d52072c779574e1cc29e6ca73ce24fe982768d90ce
5
5
  SHA512:
6
- metadata.gz: 3cf6042d5c6cb2203e2505a4db581263e4bbe99475b1928558ee4a541a73d60b16c3d162199a11b103240e02f9ec09ece7c93f0b05fed10660c5fd84cec32907
7
- data.tar.gz: 22d4e5addfb2efd94536334fddbb97f6cdd99237ca5215f6132b683ecce46bdae00d8e002239cfcc40ec26d0a37ff7b6fff08cb2a001518bb47a1a7bfaafc0f7
6
+ metadata.gz: bd3b6ab784cf9318ce46aa572b4e0c3c7e316147e1a56404a8c316a104a67c4b12f5e3805c6f349b0e98fa54773ba53ba7fa532d6e7f6f91a1c442dc10a436ca
7
+ data.tar.gz: 34126e658fce4a4c1ee29587ee598d72e2068c1c99cec359d0c373c13a0d271aefe53119b22ddda3e055b78b6e75c3c1d02964ea7301a76c45457216a68b4fe2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.1] - 2024-12-31
4
+
5
+ - Refactor: Improve implementation
6
+ - Test: Improve tests
7
+
8
+ ## [2.2.0] - 2024-12-31
9
+
10
+ - New: Raise an error when trying to assign nil to max_size, ttl, or ignore_nil
11
+ - Fix: Fix a bug where ignore_nil was not updated when ignore_nil was specified as false
12
+ - Fix: Fix a bug where items with nil value were deleted when ignore_nil was changed
13
+ - Refactor: Improve implementation
14
+ - Test: Improve tests
15
+ - Other: Improve CI
16
+ - Other: Improve documents
17
+
3
18
  ## [2.1.0] - 2024-12-30
4
19
 
5
20
  - New: Set default max_size to 1000
data/README.md CHANGED
@@ -93,7 +93,7 @@ cache.to_a
93
93
  # => [[:b, '2'], [:a, '1']]
94
94
 
95
95
  # Now we advance time 5 min 30 sec into the future.
96
- Timecop.freeze(Time.now + 330)
96
+ Timecop.freeze(Time.now + ((5 * 60) + 30))
97
97
 
98
98
  # And we see that the expired values have been evicted.
99
99
  cache.to_a
@@ -104,7 +104,7 @@ cache.to_a
104
104
  cache[:a] = '1'
105
105
  cache[:b] = '2'
106
106
 
107
- Timecop.freeze(Time.now + 330)
107
+ Timecop.freeze(Time.now + ((5 * 60) + 30))
108
108
 
109
109
  cache.ttl = 10 * 60
110
110
 
@@ -115,7 +115,7 @@ cache.to_a
115
115
  # => [[:b, '2'], [:a, '1']]
116
116
 
117
117
  # TTL eviction can be triggered manually with the #expire method.
118
- Timecop.freeze(Time.now + 330)
118
+ Timecop.freeze(Time.now + ((5 * 60) + 30))
119
119
 
120
120
  cache.expire
121
121
  cache.to_a
@@ -162,7 +162,7 @@ cache = LruRedux::TTL::ThreadSafeCache.new(100, 5 * 60)
162
162
 
163
163
  ## Contributing
164
164
 
165
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/abcd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cadenza-tech/sin_lru_redux/blob/main/CODE_OF_CONDUCT.md).
165
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cadenza-tech/sin_lru_redux. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cadenza-tech/sin_lru_redux/blob/main/CODE_OF_CONDUCT.md).
166
166
 
167
167
  ## License
168
168
 
@@ -18,8 +18,6 @@ class LruRedux::Cache
18
18
  end
19
19
 
20
20
  def max_size=(new_max_size)
21
- new_max_size ||= @max_size
22
-
23
21
  validate_max_size!(new_max_size)
24
22
 
25
23
  @max_size = new_max_size
@@ -31,8 +29,6 @@ class LruRedux::Cache
31
29
  end
32
30
 
33
31
  def ignore_nil=(new_ignore_nil)
34
- new_ignore_nil ||= @ignore_nil
35
-
36
32
  validate_ignore_nil!(new_ignore_nil)
37
33
 
38
34
  @ignore_nil = new_ignore_nil
@@ -144,10 +140,14 @@ class LruRedux::Cache
144
140
 
145
141
  if RUBY_VERSION >= '2.6.0'
146
142
  def evict_nil
143
+ return unless @ignore_nil
144
+
147
145
  @data.compact!
148
146
  end
149
147
  else
150
148
  def evict_nil
149
+ return unless @ignore_nil
150
+
151
151
  @data.reject! { |_key, value| value.nil? }
152
152
  end
153
153
  end
@@ -24,17 +24,14 @@ module LruRedux
24
24
  end
25
25
 
26
26
  def max_size=(new_max_size)
27
- new_max_size ||= @max_size
28
-
29
27
  validate_max_size!(new_max_size)
30
28
 
31
29
  @max_size = new_max_size
32
- resize
30
+ evict_expired
31
+ evict_excess
33
32
  end
34
33
 
35
34
  def ttl=(new_ttl)
36
- new_ttl ||= @ttl
37
-
38
35
  validate_ttl!(new_ttl)
39
36
 
40
37
  @ttl = new_ttl
@@ -42,8 +39,6 @@ module LruRedux
42
39
  end
43
40
 
44
41
  def ignore_nil=(new_ignore_nil)
45
- new_ignore_nil ||= @ignore_nil
46
-
47
42
  validate_ignore_nil!(new_ignore_nil)
48
43
 
49
44
  @ignore_nil = new_ignore_nil
@@ -192,9 +187,11 @@ module LruRedux
192
187
  raise ArgumentError.new("Invalid ignore_nil: #{ignore_nil.inspect}")
193
188
  end
194
189
 
195
- def resize
196
- evict_expired
197
- evict_if_exceeded
190
+ def evict_excess
191
+ while @data_lru.size > @max_size
192
+ @data_lru.shift
193
+ @data_ttl.shift
194
+ end
198
195
  end
199
196
 
200
197
  def evict_expired
@@ -209,18 +206,6 @@ module LruRedux
209
206
  end
210
207
  end
211
208
 
212
- def evict_if_exceeded
213
- evict_least_recently_used while @data_lru.size > @max_size
214
- end
215
-
216
- def evict_least_recently_used
217
- return if @data_lru.empty?
218
-
219
- oldest_key, _value = @data_lru.first
220
- @data_lru.delete(oldest_key)
221
- @data_ttl.delete(oldest_key)
222
- end
223
-
224
209
  def evict_nil
225
210
  return unless @ignore_nil
226
211
 
@@ -241,7 +226,7 @@ module LruRedux
241
226
  @data_lru[key] = value
242
227
  @data_ttl[key] = Time.now.to_f
243
228
  end
244
- evict_if_exceeded
229
+ evict_excess
245
230
  value
246
231
  end
247
232
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LruRedux
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.1'
5
5
  end
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.1.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-12-30 00:00:00.000000000 Z
10
+ date: 2024-12-31 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.1.0
36
+ homepage: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.2.1
37
37
  licenses:
38
38
  - MIT
39
39
  metadata:
40
- homepage_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.1.0
41
- source_code_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.1.0
42
- changelog_uri: https://github.com/cadenza-tech/sin_lru_redux/blob/v2.1.0/CHANGELOG.md
40
+ homepage_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.2.1
41
+ source_code_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.2.1
42
+ changelog_uri: https://github.com/cadenza-tech/sin_lru_redux/blob/v2.2.1/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.1.0
44
+ documentation_uri: https://rubydoc.info/gems/sin_lru_redux/2.2.1
45
45
  rubygems_mfa_required: 'true'
46
46
  rdoc_options: []
47
47
  require_paths: