Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ AllCops:
Exclude:
- 'gemfiles/**/*'

Layout/AccessModifierIndentation:
Enabled: false
Layout/CommentIndentation:
Enabled: false
Layout/IndentationConsistency:
Enabled: false

Style/AccessModifierDeclarations:
Enabled: false

Naming/MethodParameterName:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- '*.gemspec'

# ActiveSupport cache #fetch only calls the block on a miss, so the block form
# is not the same as the Hash#fetch default value form.
Expand All @@ -47,11 +38,11 @@ Metrics/ModuleLength:
Style/Documentation:
Enabled: false

# The generated finder methods in this file are long heredocs.
Metrics/MethodLength:
Enabled: false

Naming/VariableNumber:
Enabled: false
Exclude:
- 'lib/active_remote/cached.rb'
- 'spec/**/*'

Style/HashSyntax:
Description: >-
Expand All @@ -65,6 +56,3 @@ Style/HashSyntax:
# Use lambdas instead of stabbys
Style/Lambda:
EnforcedStyle: lambda

Style/MissingRespondToMissing:
Enabled: false
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,44 @@ CI runs this matrix on Ruby 3.1, Ruby 3.4, JRuby 9.4, and JRuby 10.0.
`active_remote` 8.0 requires Ruby 3.2 or later. CI does not run that
version on Ruby 3.1 or JRuby 9.4.

## Upgrading to 1.2.0

### Every cache key changes

Before 1.2.0 the cache key held only the argument values, joined with no
separator. Three different finders shared one cache entry:

```ruby
Customer.cached_find_by_name_and_email("x", "y") # key: "xy"
Customer.cached_find_by_city_and_state("x", "y") # key: "xy" same entry
Customer.cached_find_by_id("xy") # key: "xy" same entry
```

The key now names each field, so each finder gets its own entry:

```ruby
Customer.cached_find_by_name_and_email("x", "y") # key: "email.y/name.x"
```

Every existing cache entry becomes a miss after the upgrade. Expect one cold
period. The gem already causes this on an ActiveSupport upgrade, through
`RUBY_AND_ACTIVE_SUPPORT_VERSION`.

### A bad call now raises

A dynamic finder called with too few arguments used to pass `nil` for the
missing field and cache the result. It now raises `ArgumentError`:

```ruby
Customer.cached_find_by_email_and_name("only_one") # => ArgumentError
```

### The cache provider validator raises a new class

`ActiveRemote::Cached::Cache::InvalidCacheProvider` replaces the bare
`RuntimeError` that `ActiveRemote::Cached.cache` raised for a provider that is
missing a method.

## Known behavior

Two behaviors are recorded in the specs. Neither is fixed. Read
Expand All @@ -161,9 +199,10 @@ method named `not_cached_find_by_guid` resolves to `cached_find_by_guid`.

### A subclass has its own empty cached_methods list

A subclass inherits the finder methods its parent defined. It does not inherit
the `cached_methods` list. The parent accepts the finder arguments in any
order. The subclass accepts them only in the order the method was defined.
A subclass inherits the finder methods its parent defined, and the options
those finders were declared with. It does not inherit the `cached_methods`
list. The parent accepts the finder arguments in any order. The subclass
accepts them only in the order the method was defined.

```ruby
Parent.cached_find_by_beta_and_alpha('B', 'A') # works
Expand Down
30 changes: 26 additions & 4 deletions active_remote-cached.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,45 @@ lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'active_remote/cached/version'

HOMEPAGE = 'https://github.com/mxenabled/active_remote-cached'

# git ls-files returns nothing outside a checkout, so a build from a released
# tarball needs the glob.
def gem_files
files = if File.directory?(File.join(__dir__, '.git'))
`git ls-files`.split($INPUT_RECORD_SEPARATOR)
else
Dir.glob('{lib,spec}/**/*', File::FNM_DOTMATCH) +
%w[LICENSE.txt README.md Rakefile Appraisals active_remote-cached.gemspec]
end

files.reject { |file| File.directory?(file) }
end

Gem::Specification.new do |gem|
gem.name = 'active_remote-cached'
gem.version = ActiveRemote::Cached::VERSION
gem.authors = ['Brandon Dewitt', 'MXDevExperience']
gem.email = ['brandonsdewitt@gmail.com', 'devexperience@mx.com']
gem.description = ' Provides "cached" finders and a DSL to enumerate which finders should have cached versions '
gem.summary = ' Provides a configuration for caching mechanisms and finders on ActiveRemote models'
gem.homepage = ''
gem.homepage = HOMEPAGE
gem.license = 'MIT'

gem.metadata = {
'homepage_uri' => HOMEPAGE,
'source_code_uri' => HOMEPAGE,
'rubygems_mfa_required' => 'true'
}

gem.required_ruby_version = '>= 3.1'
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
gem.files = gem_files
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']

gem.add_dependency 'active_remote', '>= 6.1'
gem.add_dependency 'activesupport'
# NullStore and ActiveSupport::VERSION::STRING. Matches the active_remote floor.
gem.add_dependency 'activesupport', '>= 6.1'

gem.add_development_dependency 'appraisal'
gem.add_development_dependency 'bundler'
Expand Down
Loading
Loading