leveled_cache 0.1.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a86654509725147ae338c2043e6d7f8ba9d5df587b2c34cf93a65000c30d10d
4
- data.tar.gz: ca9185afc78fe514d66abb0264cb45031c88c512f9cfec7362dcb65bdcf2881c
3
+ metadata.gz: 8a1044673841aded566b48eb3bd310619dca57ce3f2722768e9c47c9379bd68b
4
+ data.tar.gz: a3dcc54d533abbc3ed3ab89d08bd851b62de5c2461af683523ca26f7ef5d2e83
5
5
  SHA512:
6
- metadata.gz: 4a316bcdfee2317c1b63b52660e169bfa5b115b3aed273cb4dea60051f81ff47ce417bf33c44481e6f496bafdfef35a9b5ff406ca8f07c685baa0be8d32dd749
7
- data.tar.gz: 16ef1640ba78fc68f7823bea32bc8278654fa6e4ac5f9af36aba079abc3ab73a99c58e10f471cbcc6c0fea03743b435ec749c46adb8df0d8551a0d5424139546
6
+ metadata.gz: 8317ac588eb5d751c96558c8f4c9fde807a98f6cc19265dab01a2e8c776a89133e1805fb438899d40b1fa3638c21581a46d2fc489cdb054e15bab3335792e7b5
7
+ data.tar.gz: c52bf449a0276e50e7b57627aff77ccf9916a3b3bf8c1d9b03c886706ec4fa37e039a223ea985b28e74fc1442a2161a499dd0270dbd504b5037f4549fdda6cd5
data/Appraisals CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w[6.1 7.0 7.1].each do |version|
3
+ %w[6.1 7.0 7.1 7.2].each do |version|
4
4
  appraise "activesupport-#{version}" do
5
5
  gem "activesupport", "~> #{version}.0"
6
6
  end
data/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2024-08-15
2
+
3
+ - Optimize `read_multi`
4
+ - Implement `write_multi`
5
+ - Fix `delete` so that keys aren't double-namespaced
6
+ - Support nested `LeveledCache`
7
+
8
+ ## [0.2.0] - 2024-02-26
9
+
10
+ - Support `ActiveSupport::Cache.lookup_store`
11
+ - `#write` and `#delete` now return responses from underlying caches
2
12
 
3
13
  ## [0.1.0] - 2024-02-13
4
14
 
data/Gemfile CHANGED
@@ -7,6 +7,4 @@ gemspec
7
7
  gem "appraisal"
8
8
  gem "rake", "~> 13.0"
9
9
  gem "rspec", "~> 3.0"
10
- gem "rubocop", "~> 1"
11
- gem "rubocop-rake", "~> 0"
12
- gem "rubocop-rspec", "~> 2.0"
10
+ gem "standardrb", "~> 1"
data/README.md CHANGED
@@ -47,7 +47,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
47
47
 
48
48
  ## Contributing
49
49
 
50
- Bug reports and pull requests are welcome on GitHub at https://github.com/dpirotte/leveled_cache. 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/[USERNAME]/activesupport-cache-leveled_proxy/blob/main/CODE_OF_CONDUCT.md).
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dpirotte/leveled_cache. 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/dpirotte/leveled_cache/blob/main/CODE_OF_CONDUCT.md).
51
51
 
52
52
  ## License
53
53
 
@@ -55,4 +55,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
55
55
 
56
56
  ## Code of Conduct
57
57
 
58
- Everyone interacting in the LeveledCache project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activesupport-cache-leveled_proxy/blob/main/CODE_OF_CONDUCT.md).
58
+ Everyone interacting in the LeveledCache project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dpirotte/leveled_cache/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -2,11 +2,8 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "standard/rake"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
9
+ task default: %i[spec standard]
@@ -5,9 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake", "~> 13.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem "rubocop", "~> 1"
9
- gem "rubocop-rake", "~> 0"
10
- gem "rubocop-rspec", "~> 2.0"
8
+ gem "standardrb", "~> 1"
11
9
  gem "activesupport", "~> 6.1.0"
12
10
 
13
11
  gemspec path: "../"
@@ -5,9 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake", "~> 13.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem "rubocop", "~> 1"
9
- gem "rubocop-rake", "~> 0"
10
- gem "rubocop-rspec", "~> 2.0"
8
+ gem "standardrb", "~> 1"
11
9
  gem "activesupport", "~> 7.0.0"
12
10
 
13
11
  gemspec path: "../"
@@ -5,9 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake", "~> 13.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem "rubocop", "~> 1"
9
- gem "rubocop-rake", "~> 0"
10
- gem "rubocop-rspec", "~> 2.0"
8
+ gem "standardrb", "~> 1"
11
9
  gem "activesupport", "~> 7.1.0"
12
10
 
13
11
  gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "rake", "~> 13.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "standardrb", "~> 1"
9
+ gem "activesupport", "~> 7.2.0"
10
+
11
+ gemspec path: "../"
@@ -5,9 +5,7 @@ source "https://rubygems.org"
5
5
  gem "appraisal"
6
6
  gem "rake", "~> 13.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem "rubocop", "~> 1"
9
- gem "rubocop-rake", "~> 0"
10
- gem "rubocop-rspec", "~> 2.0"
8
+ gem "standardrb", "~> 1"
11
9
  gem "activesupport", git: "https://github.com/rails/rails", glob: "activesupport/*.gemspec"
12
10
 
13
11
  gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ module Cache
5
+ LeveledCacheStore = LeveledCache::Store
6
+ end
7
+ end
@@ -22,8 +22,6 @@ module LeveledCache
22
22
  # care to configure underlying caches accordingly. For example, it may
23
23
  # be desirable to use NullCoder on an earlier MemoryStore.
24
24
  class Store < ActiveSupport::Cache::Store
25
- VERSION = "0.1.0"
26
-
27
25
  # Create a new LeveledCacheProxy that calls cache methods on
28
26
  # one or more underlying caches in order.
29
27
  #
@@ -72,6 +70,15 @@ module LeveledCache
72
70
  read_entry(name, **options)
73
71
  end
74
72
 
73
+ # Reads data from the caches in order using the given keys. Data
74
+ # is returned from the first cache level with data for a key.
75
+ # Otherwise, +{}+ is returned.
76
+ #
77
+ # Options are passed through to the underlying caches.
78
+ def read_multi(*names, **options)
79
+ read_multi_entries(names, **options)
80
+ end
81
+
75
82
  # Writes the value to all cache levels with the provided key.
76
83
  #
77
84
  # Options are passed through to the underlying caches.
@@ -79,6 +86,20 @@ module LeveledCache
79
86
  write_entry(name, value, **options)
80
87
  end
81
88
 
89
+ # Deletes the value from all cache levels with the provided key.
90
+ #
91
+ # Options are passed through to the underlying caches.
92
+ def delete(name, **options)
93
+ delete_entry(name, **options)
94
+ end
95
+
96
+ # Writes the key value pairs to all cache levels.
97
+ #
98
+ # Options are passed through to the underlying caches.
99
+ def write_multi(hash, **options)
100
+ write_multi_entries(hash, **options)
101
+ end
102
+
82
103
  private
83
104
 
84
105
  # Recursively `fetch_multi` on each cache. Missing values
@@ -87,17 +108,22 @@ module LeveledCache
87
108
  def _fetch_multi(caches, names, options, &)
88
109
  first, *rest = caches
89
110
 
90
- reads = first.read_multi(*names, **options)
111
+ reads = if first.is_a?(self.class)
112
+ first.fetch_multi(*names, **options, &)
113
+ else
114
+ first.read_multi(*names, **options)
115
+ end
116
+
91
117
  missing = names - reads.keys
92
118
 
93
119
  if missing.any?
94
120
  writes = if rest.any?
95
- _fetch_multi(rest, missing, options, &)
96
- else
97
- missing.index_with(&)
98
- end
121
+ _fetch_multi(rest, missing, options, &)
122
+ else
123
+ missing.index_with(&)
124
+ end
99
125
 
100
- first.write_multi(writes, options)
126
+ first.write_multi(writes, **options)
101
127
  reads.merge!(writes)
102
128
  end
103
129
 
@@ -109,7 +135,7 @@ module LeveledCache
109
135
  def _fetch(caches, name, options, &block)
110
136
  first, *rest = caches
111
137
 
112
- first.fetch(name, options) do
138
+ first.fetch(name, **options) do
113
139
  if rest.any?
114
140
  _fetch(rest, name, options, &block)
115
141
  else
@@ -120,19 +146,43 @@ module LeveledCache
120
146
 
121
147
  def read_entry(key, **options)
122
148
  @caches.lazy.map do |cache|
123
- cache.read(key, options)
149
+ cache.read(key, **options)
124
150
  end.compact.first
125
151
  end
126
152
 
127
153
  def write_entry(key, entry, **options)
128
- @caches.each do |cache|
129
- cache.write(key, entry, options)
154
+ @caches.map do |cache|
155
+ cache.write(key, entry, **options)
130
156
  end
131
157
  end
132
158
 
133
159
  def delete_entry(key, **options)
134
- @caches.each do |cache|
135
- cache.delete(key, options)
160
+ @caches.map do |cache|
161
+ cache.delete(key, **options)
162
+ end
163
+ end
164
+
165
+ def read_multi_entries(*keys, **options)
166
+ _read_multi_entries(@caches, *keys, **options)
167
+ end
168
+
169
+ def _read_multi_entries(caches, keys, **options)
170
+ first, *rest = caches
171
+
172
+ reads = first.read_multi(*keys, **options)
173
+
174
+ missing = keys - reads.keys
175
+
176
+ if missing.any? && rest.any?
177
+ reads.merge!(_read_multi_entries(rest, missing, **options))
178
+ end
179
+
180
+ reads
181
+ end
182
+
183
+ def write_multi_entries(hash, **options)
184
+ @caches.map do |cache|
185
+ cache.write_multi(hash)
136
186
  end
137
187
  end
138
188
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LeveledCache
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/leveled_cache.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "leveled_cache/store"
4
+ require "leveled_cache/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leveled_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Pirotte
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-16 00:00:00.000000000 Z
11
+ date: 2024-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '6.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,8 +29,8 @@ dependencies:
29
29
  version: '6.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
33
- description:
32
+ version: '8.0'
33
+ description:
34
34
  email:
35
35
  - dpirotte@gmail.com
36
36
  executables: []
@@ -38,7 +38,6 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - ".rspec"
41
- - ".rubocop.yml"
42
41
  - Appraisals
43
42
  - CHANGELOG.md
44
43
  - CODE_OF_CONDUCT.md
@@ -49,7 +48,9 @@ files:
49
48
  - gemfiles/activesupport_6.1.gemfile
50
49
  - gemfiles/activesupport_7.0.gemfile
51
50
  - gemfiles/activesupport_7.1.gemfile
51
+ - gemfiles/activesupport_7.2.gemfile
52
52
  - gemfiles/activesupport_main.gemfile
53
+ - lib/active_support/cache/leveled_cache_store.rb
53
54
  - lib/leveled_cache.rb
54
55
  - lib/leveled_cache/store.rb
55
56
  - lib/leveled_cache/version.rb
@@ -61,7 +62,7 @@ metadata:
61
62
  rubygems_mfa_required: 'true'
62
63
  source_code_uri: https://github.com/dpirotte/leveled_cache
63
64
  changelog_uri: https://github.com/dpirotte/leveled_cache/blob/main/CHANGELOG.md
64
- post_install_message:
65
+ post_install_message:
65
66
  rdoc_options: []
66
67
  require_paths:
67
68
  - lib
@@ -76,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  - !ruby/object:Gem::Version
77
78
  version: '0'
78
79
  requirements: []
79
- rubygems_version: 3.4.1
80
- signing_key:
80
+ rubygems_version: 3.3.23
81
+ signing_key:
81
82
  specification_version: 4
82
83
  summary: ActiveSupport::Cache that wraps multiple levels of caches
83
84
  test_files: []
data/.rubocop.yml DELETED
@@ -1,50 +0,0 @@
1
- require:
2
- - rubocop-rake
3
- - rubocop-rspec
4
-
5
- AllCops:
6
- NewCops: enable
7
- TargetRubyVersion: 3.1
8
-
9
- Bundler/OrderedGems:
10
- Exclude:
11
- - gemfiles/*
12
-
13
- Metrics/BlockLength:
14
- Max: 200
15
-
16
- Metrics/MethodLength:
17
- Max: 16
18
-
19
- Style/ArgumentsForwarding:
20
- UseAnonymousForwarding: false
21
-
22
- Style/FrozenStringLiteralComment:
23
- Exclude:
24
- - gemfiles/*
25
-
26
- Style/StringLiterals:
27
- Enabled: true
28
- EnforcedStyle: double_quotes
29
-
30
- Style/StringLiteralsInInterpolation:
31
- Enabled: true
32
- EnforcedStyle: double_quotes
33
-
34
- Layout/LineLength:
35
- Max: 120
36
-
37
- Lint/MissingSuper:
38
- Enabled: false
39
-
40
- RSpec/ExampleLength:
41
- Max: 7
42
-
43
- RSpec/MessageSpies:
44
- EnforcedStyle: receive
45
-
46
- RSpec/MultipleExpectations:
47
- Max: 5
48
-
49
- RSpec/MultipleMemoizedHelpers:
50
- Max: 6