Skip to content
Open
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
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.
#
# This workflow will install a prebuilt Ruby version, install dependencies, and
# run tests and linters.
name: "active_remote-cached"
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [ '3.2', '3.1', '3.0', '2.7', 'jruby-9.4' ]
gemfile: [ 'rails60', 'rails61', 'rails70' ]
env:
RAILS_ENV: test
steps:
- name: Checkout code
uses: actions/checkout@v3
# Add or replace dependency steps here
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby-version }}
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
# Add or replace test runners here
- name: Run tests
run: bundle exec rake test
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
old_tests:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [ '2.6', 'jruby-9.3' ]
gemfile: [ 'rails60', 'rails61' ]
env:
RAILS_ENV: test
steps:
- name: Checkout code
uses: actions/checkout@v3
# Add or replace dependency steps here
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby-version }}
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
# Add or replace test runners here
- name: Run tests
run: bundle exec rake test
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ end

_*This is already done for you in Rails_

Then declare some cache finder methods. Cached finders can be defined for individual fields or defined as composites for mulitple fields
Then declare some cache finder methods. Cached finders can be defined for individual fields or defined as composites for
multiple fields

```ruby
class Customer < ::ActiveRemote::Base
Expand All @@ -42,7 +43,8 @@ class Customer < ::ActiveRemote::Base
end
```

Now that you have a model that has cached finders on it you can use the `cached_search`, `cached_find`, or dynamic cached finder methods on the model to use the cache before you issue the AR search/find method.
Now that you have a model that has cached finders on it you can use the `cached_search`, `cached_find`, or dynamic
cached finder methods on the model to use the cache before you issue the AR search/find method.

```ruby
customer = ::Customer.cached_find_by_id(1) # => <Customer id=1>
Expand All @@ -62,13 +64,14 @@ customer = ::Customer.cached_find_by_name("name") # => NoMethodError

### Configuring the cache provider

ActiveRemote::Cached relies on an ActiveSupport::Cache-compatible cache provider. The cache is initialized with a simple memory store (defaults to 32MB), but can be overridden via `ActiveRemote::Cached.cache`:
ActiveRemote::Cached relies on an ActiveSupport::Cache-compatible cache provider. The cache is initialized with a simple
memory store (defaults to 32MB), but can be overridden via `ActiveRemote::Cached.cache`:

```ruby
ActiveRemote::Cached.cache(Your::ActiveSupport::Cache::Compatible::Provider.new)
```

In Rails apps, the memory store is replaced the whatever Rails is using as it's cache store.
In Rails apps, the memory store is replaced with whatever Rails is using as it's cache store.

#### Default options

Expand All @@ -78,11 +81,19 @@ The default cache options used when interacting with the cache can be specified
ActiveRemote::Cached.default_options(:expires_in => 1.hour)
```

In Rails apps, the :race_condition_ttl option defaults to 5 seconds.
In Rails apps, the options are:

| Configuration Option | Default | Description |
|-----------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `:race_condition_ttl` | `5.seconds` | See [ActiveSupport::Cache::Store documentation](https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html) |
| `:expires_in` | `5.minutes` | See [ActiveSupport::Cache::Store documentation](https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html) |
| `:handle_cache_error` | `false` | When true, cache errors will be handled and optionally sent to handler and return value will be as if cache missed, when cache errors will raise to application |
| `:cache_error_proc` | `nil` | Can be a proc that accepts a single value, the cache error raised, to be used in any kind of error handling you might want |

#### Local overrides

Each finder as takes an optional options hash that will override the options passed to the caching provider (override from the global defaults setup for ActiveRemote::Cached)
Each finder takes an optional options hash that will override the options passed to the caching provider (override from
the global defaults setup for ActiveRemote::Cached)

```ruby
customer = ::Customer.cached_find_by_id(1, :expires_in => 15.minutes)
Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails60.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "activesupport", "~> 6.0.0"
gemspec path: "../"
71 changes: 71 additions & 0 deletions gemfiles/rails60.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
PATH
remote: ..
specs:
active_remote-cached (0.2.0)
active_remote
activesupport

GEM
remote: https://rubygems.org/
specs:
active_remote (6.0.2)
activemodel (~> 6.0.0)
activesupport (~> 6.0.0)
protobuf (>= 3.0)
activemodel (6.0.6.1)
activesupport (= 6.0.6.1)
activesupport (6.0.6.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
coderay (1.1.3)
concurrent-ruby (1.2.2)
ffi (1.15.5-java)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
middleware (0.1.0)
minitest (5.18.0)
mocha (2.0.2)
ruby2_keywords (>= 0.0.5)
protobuf (3.10.7)
activesupport (>= 3.2)
middleware
thor
thread_safe
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry (0.14.2-java)
coderay (~> 1.1)
method_source (~> 1.0)
spoon (~> 0.0)
rake (13.0.6)
ruby2_keywords (0.0.5)
spoon (0.0.6)
ffi
thor (1.2.1)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tzinfo (1.2.11)
thread_safe (~> 0.1)
zeitwerk (2.6.7)

PLATFORMS
universal-java-1.8
universal-java-11
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
active_remote-cached!
activesupport (~> 6.0.0)
bundler
mocha
pry
rake

BUNDLED WITH
2.4.12
4 changes: 4 additions & 0 deletions gemfiles/rails61.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "activesupport", "~> 6.1.0"
gemspec path: "../"
71 changes: 71 additions & 0 deletions gemfiles/rails61.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
PATH
remote: ..
specs:
active_remote-cached (0.2.0)
active_remote
activesupport

GEM
remote: https://rubygems.org/
specs:
active_remote (6.1.1)
activemodel (~> 6.1.0)
activesupport (~> 6.1.0)
protobuf (>= 3.0)
activemodel (6.1.7.3)
activesupport (= 6.1.7.3)
activesupport (6.1.7.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
coderay (1.1.3)
concurrent-ruby (1.2.2)
ffi (1.15.5-java)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
middleware (0.1.0)
minitest (5.18.0)
mocha (2.0.2)
ruby2_keywords (>= 0.0.5)
protobuf (3.10.7)
activesupport (>= 3.2)
middleware
thor
thread_safe
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry (0.14.2-java)
coderay (~> 1.1)
method_source (~> 1.0)
spoon (~> 0.0)
rake (13.0.6)
ruby2_keywords (0.0.5)
spoon (0.0.6)
ffi
thor (1.2.1)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
zeitwerk (2.6.7)

PLATFORMS
universal-java-1.8
universal-java-11
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
active_remote-cached!
activesupport (~> 6.1.0)
bundler
mocha
pry
rake

BUNDLED WITH
2.4.12
4 changes: 4 additions & 0 deletions gemfiles/rails70.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem "activesupport", "~> 7.0.0"
gemspec path: "../"
69 changes: 69 additions & 0 deletions gemfiles/rails70.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
PATH
remote: ..
specs:
active_remote-cached (0.2.0)
active_remote
activesupport

GEM
remote: https://rubygems.org/
specs:
active_remote (3.1.2)
activemodel (>= 4.0)
activesupport (>= 4.0)
protobuf (>= 3.0)
activemodel (7.0.4.3)
activesupport (= 7.0.4.3)
activesupport (7.0.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
ffi (1.15.5-java)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
middleware (0.1.0)
minitest (5.18.0)
mocha (2.0.2)
ruby2_keywords (>= 0.0.5)
protobuf (3.10.7)
activesupport (>= 3.2)
middleware
thor
thread_safe
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry (0.14.2-java)
coderay (~> 1.1)
method_source (~> 1.0)
spoon (~> 0.0)
rake (13.0.6)
ruby2_keywords (0.0.5)
spoon (0.0.6)
ffi
thor (1.2.1)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)

PLATFORMS
universal-java-1.8
universal-java-11
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
active_remote-cached!
activesupport (~> 7.0.0)
bundler
mocha
pry
rake

BUNDLED WITH
2.4.12
Loading