sin_lru_redux 2.1.0 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10d8a07bc1dcf5957a24804163d1ac62086dac85b3cefce3ff305757231a3696
4
- data.tar.gz: 4820d035651c937d4486800a4ca3b1fda48ccfb1118d0bcd420bf49b88c5583e
3
+ metadata.gz: 3a4f3922e84907ba0de45efa46ee990b5947f28a7cd0c636de9ed268bc8a2335
4
+ data.tar.gz: 4e0da38bf6e25d814751eb2304a409dde4da530db49dc17b9c7fbd44ddb16e1b
5
5
  SHA512:
6
- metadata.gz: 3cf6042d5c6cb2203e2505a4db581263e4bbe99475b1928558ee4a541a73d60b16c3d162199a11b103240e02f9ec09ece7c93f0b05fed10660c5fd84cec32907
7
- data.tar.gz: 22d4e5addfb2efd94536334fddbb97f6cdd99237ca5215f6132b683ecce46bdae00d8e002239cfcc40ec26d0a37ff7b6fff08cb2a001518bb47a1a7bfaafc0f7
6
+ metadata.gz: ce0f773d075691a31efb284a2ce23f860cf225d38450020ca32a280e22fb39a1941e79f0c7adb775fbf07c5bf1ecd93241b55b468b500abbc64f2698bfa6e60e
7
+ data.tar.gz: 58b1096ed7841aa618080bd85fbe00d42f056e8784cf9ce0ee03ec5b82792bfcd497abd9c90026e1374b5b513804f78c517ec5f648bef80ed23b94db4b650bd4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0] - 2024-12-31
4
+
5
+ - New: Raise an error when trying to assign nil to max_size, ttl, or ignore_nil
6
+ - Fix: Fix a bug where ignore_nil was not updated when ignore_nil was specified as false
7
+ - Fix: Fix a bug where items with nil value were deleted when ignore_nil was changed
8
+ - Refactor: Improve implementation
9
+ - Test: Improve tests
10
+ - Other: Improve CI
11
+ - Other: Improve documents
12
+
3
13
  ## [2.1.0] - 2024-12-30
4
14
 
5
15
  - 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,11 +187,6 @@ 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
198
- end
199
-
200
190
  def evict_expired
201
191
  return if @ttl == :none
202
192
 
@@ -209,7 +199,7 @@ module LruRedux
209
199
  end
210
200
  end
211
201
 
212
- def evict_if_exceeded
202
+ def evict_excess
213
203
  evict_least_recently_used while @data_lru.size > @max_size
214
204
  end
215
205
 
@@ -241,7 +231,7 @@ module LruRedux
241
231
  @data_lru[key] = value
242
232
  @data_ttl[key] = Time.now.to_f
243
233
  end
244
- evict_if_exceeded
234
+ evict_excess
245
235
  value
246
236
  end
247
237
  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.0'
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.0
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.0
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.0
41
+ source_code_uri: https://github.com/cadenza-tech/sin_lru_redux/tree/v2.2.0
42
+ changelog_uri: https://github.com/cadenza-tech/sin_lru_redux/blob/v2.2.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.1.0
44
+ documentation_uri: https://rubydoc.info/gems/sin_lru_redux/2.2.0
45
45
  rubygems_mfa_required: 'true'
46
46
  rdoc_options: []
47
47
  require_paths: