sin_lru_redux 2.2.1 → 2.3.0

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
  SHA256:
3
- metadata.gz: 62aedb1e0b7730269fe2f336ae70bdfd158cf38efd0827c8fae3bd4810e4b0dc
4
- data.tar.gz: db0572e99799e265c3d6b8d52072c779574e1cc29e6ca73ce24fe982768d90ce
3
+ metadata.gz: a205e8ba667a41a33f3b7fdb9d86e6ab3cc5623aff0998a31e00899db3069535
4
+ data.tar.gz: 6b3cad6832644bdc3c8ec26e821f7ff855f1591c99be6a127ba55b048943f1e2
5
5
  SHA512:
6
- metadata.gz: bd3b6ab784cf9318ce46aa572b4e0c3c7e316147e1a56404a8c316a104a67c4b12f5e3805c6f349b0e98fa54773ba53ba7fa532d6e7f6f91a1c442dc10a436ca
7
- data.tar.gz: 34126e658fce4a4c1ee29587ee598d72e2068c1c99cec359d0c373c13a0d271aefe53119b22ddda3e055b78b6e75c3c1d02964ea7301a76c45457216a68b4fe2
6
+ metadata.gz: 63f527c1469a8cc98b48be9c9248bd6406d75db63443930368e328106048d4aafaba3f9f560d63ab4e535c832d9485b90e69039c5b496999fd91535411116a1e
7
+ data.tar.gz: f10d3bb3ec140660b562f8246eaa89acf1bbe6b497b5d283d5494b4ac57cce1621ab932fc4f55cc70dc995fd933ba12fa71d72311683e31c93a2bd37d184fe4b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.3.0] - 2025-1-1
4
+
5
+ - New: Add alias method `length` and `size` for `count`
6
+ - Refactor: Improve implementation
7
+ - Test: Update tests
8
+ - Other: Improve README.md
9
+
3
10
  ## [2.2.1] - 2024-12-31
4
11
 
5
12
  - Refactor: Improve implementation
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 { |k, v| puts "#{k} #{v}"}
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.
@@ -14,7 +14,7 @@ class LruRedux::Cache
14
14
 
15
15
  @max_size = max_size
16
16
  @ignore_nil = ignore_nil
17
- @data = {}
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 = @data.delete(key) { key_found = false }
40
+ value = @data_lru.delete(key) { key_found = false }
41
41
 
42
42
  if key_found
43
- @data[key] = value
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 = @data.delete(key) { key_found = false }
53
+ value = @data_lru.delete(key) { key_found = false }
54
54
 
55
55
  if key_found
56
- @data[key] = value
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 = @data.delete(key) { key_found = false }
64
+ value = @data_lru.delete(key) { key_found = false }
65
65
  return unless key_found
66
66
 
67
- @data[key] = value
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
- @data.to_a.reverse_each(&block)
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
- @data.to_a.reverse
81
+ @data_lru.to_a.reverse
82
82
  end
83
83
 
84
84
  def values
85
- @data.values.reverse
85
+ @data_lru.values.reverse
86
86
  end
87
87
 
88
88
  def delete(key)
89
- @data.delete(key)
89
+ @data_lru.delete(key)
90
90
  end
91
91
  alias_method :evict, :delete
92
92
 
93
93
  def key?(key)
94
- @data.key?(key)
94
+ @data_lru.key?(key)
95
95
  end
96
96
  alias_method :has_key?, :key?
97
97
 
98
98
  def clear
99
- @data.clear
99
+ @data_lru.clear
100
100
  end
101
101
 
102
102
  def count
103
- @data.size
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
- @data.shift while @data.size > @max_size
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
- @data.compact!
147
+ @data_lru.compact!
146
148
  end
147
149
  else
148
150
  def evict_nil
149
151
  return unless @ignore_nil
150
152
 
151
- @data.reject! { |_key, value| value.nil? }
153
+ @data_lru.reject! { |_key, value| value.nil? }
152
154
  end
153
155
  end
154
156
 
155
157
  def store_item(key, val)
156
- @data.delete(key)
157
- @data[key] = val if !val.nil? || !@ignore_nil
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
@@ -137,6 +137,8 @@ module LruRedux
137
137
  def count
138
138
  @data_lru.size
139
139
  end
140
+ alias_method :length, :count
141
+ alias_method :size, :count
140
142
 
141
143
  def expire
142
144
  evict_expired
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LruRedux
4
- VERSION = '2.2.1'
4
+ VERSION = '2.3.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.2.1
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: 2024-12-31 00:00:00.000000000 Z
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.2.1
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.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
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.2.1
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: