Skip to content

Commit

Permalink
Merge pull request #160 from rails/latest-rails-cache-behavior
Browse files Browse the repository at this point in the history
Latest Rails cache behavior
  • Loading branch information
djmb authored Mar 13, 2024
2 parents 40ea64c + 6f672a0 commit 1fb8cb3
Show file tree
Hide file tree
Showing 27 changed files with 736 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
fail-fast: false
matrix:
ruby-version: ["3.0", "3.1", "3.2", "3.3"]
gemfile: [ rails_7, rails_7_1, rails_main ]
gemfile: [ rails_7_1, rails_main ]
database: [sqlite, postgres, mysql]
exclude:
- ruby-version: "3.0"
Expand Down
4 changes: 0 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

appraise "rails-7" do
gem "railties", github: "rails/rails", branch: "7-0-stable"
end

appraise "rails-7-1" do
gem "railties", github: "rails/rails", branch: "7-1-stable"
end
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ PATH
remote: .
specs:
solid_cache (0.5.3)
activejob (>= 7)
activerecord (>= 7)
railties (>= 7)
activejob (>= 7.1)
activerecord (>= 7.1)
railties (>= 7.1)

GEM
remote: https://rubygems.org/
Expand Down
18 changes: 7 additions & 11 deletions app/models/solid_cache/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read_multi(keys)
end

def delete_by_key(key)
delete_no_query_cache(:key_hash, key_hash_for(key))
delete_no_query_cache(:key_hash, key_hash_for(key)) > 0
end

def delete_multi(keys)
Expand All @@ -47,21 +47,17 @@ def clear_delete
in_batches.delete_all
end

def increment(key, amount)
def lock_and_write(key, &block)
transaction do
uncached do
result = lock.where(key_hash: key_hash_for(key)).pick(:key, :value)
amount += result[1].to_i if result&.first == key
write(key, amount)
amount
new_value = block.call(result&.first == key ? result[1] : nil)
write(key, new_value)
new_value
end
end
end

def decrement(key, amount)
increment(key, -amount)
end

def id_range
uncached do
pick(Arel.sql("max(id) - min(id) + 1")) || 0
Expand Down Expand Up @@ -152,9 +148,9 @@ def delete_no_query_cache(attribute, values)

# exec_delete does not clear the query cache
if connection.prepared_statements?
connection.exec_delete(sql, "#{name} Delete All", Array(values)).nonzero?
connection.exec_delete(sql, "#{name} Delete All", Array(values))
else
connection.exec_delete(sql, "#{name} Delete All").nonzero?
connection.exec_delete(sql, "#{name} Delete All")
end
end
end
Expand Down
21 changes: 0 additions & 21 deletions gemfiles/rails_7.gemfile

This file was deleted.

196 changes: 0 additions & 196 deletions gemfiles/rails_7.gemfile.lock

This file was deleted.

6 changes: 3 additions & 3 deletions gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ PATH
remote: ..
specs:
solid_cache (0.5.3)
activejob (>= 7)
activerecord (>= 7)
railties (>= 7)
activejob (>= 7.1)
activerecord (>= 7.1)
railties (>= 7.1)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/rails_main.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ PATH
remote: ..
specs:
solid_cache (0.5.3)
activejob (>= 7)
activerecord (>= 7)
railties (>= 7)
activejob (>= 7.1)
activerecord (>= 7.1)
railties (>= 7.1)

GEM
remote: https://rubygems.org/
Expand Down
Loading

0 comments on commit 1fb8cb3

Please sign in to comment.