solid_cache 1.0.0 → 1.0.2

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: 74f6b8bdfea57b8ffbe60b8f525b3907c7278f4b73d07fad2506a41b0884a14c
4
- data.tar.gz: b3af9a6526d97bcb9b5ac1fd313b9c9cf76551ae75e214479a10fe9b04d678d3
3
+ metadata.gz: d8807bd93a8e16495e40542655163d95bcfac3b9a0d96de0ccbea687899ba600
4
+ data.tar.gz: 15107cc9ed202a7c8cf01d962c7ec8182eed76c3677e86155f104fac07eae6b2
5
5
  SHA512:
6
- metadata.gz: b6503fe5c3f9d3158ec64bc054465e48f1479236b05fd3b023f4c7050b8c2c0019a546cae0c494a91da0c7b3e9abf3cc3f8f700b2d6c9853a3832b8a726d750a
7
- data.tar.gz: 38eec70ef2680b811f9f3baf42e02d5d81d72947c508f45a4ca0cd8d2c1d6d761280e5ec15261c4ca3b94fbdfe20dd1cf96a2cf871255791b41a2d11cfe8aa29
6
+ metadata.gz: 2c1bdc5f7ae9313d017388821a1792228b9ff59d9570cc46129f2b0127648aeda3e103b3f387758c37b4119010929f48452def1638dad43a90cb46d201db2274
7
+ data.tar.gz: a0352691be83a3ee2227c501235bfd7c8639ea08b717c0bcbfcf002a3901b367c142d430677afd30778cafef0918192ed4afc987b9082987524dbdc327d6e42b
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ end
36
36
  configs.each do |config|
37
37
  namespace :test do
38
38
  task config do
39
- if config.to_s.start_with?("encrypted") && ENV["TARGET_DB"] == "postgres"
39
+ if config.to_s.start_with?("encrypted") && ENV["TARGET_DB"] == "postgres" && Rails::VERSION::MAJOR <= 7
40
40
  puts "Skipping encrypted tests on PostgreSQL as binary encrypted columns are not supported by Rails yet"
41
41
  next
42
42
  end
@@ -33,7 +33,9 @@ module SolidCache
33
33
 
34
34
  def read_multi(keys)
35
35
  without_query_cache do
36
- find_by_sql([select_sql(keys), *key_hashes_for(keys)]).pluck(:key, :value).to_h
36
+ query = Arel.sql(select_sql(keys), *key_hashes_for(keys))
37
+
38
+ connection.select_all(query, "SolidCache::Entry Load").cast_values(attribute_types).to_h
37
39
  end
38
40
  end
39
41
 
@@ -84,13 +86,24 @@ module SolidCache
84
86
  connection.supports_insert_conflict_target? ? :key_hash : nil
85
87
  end
86
88
 
89
+ # This constructs and caches a SQL query for a given number of keys.
90
+ #
91
+ # The query is constructed with two bind parameters to generate an IN (...) condition,
92
+ # which is then replaced with the correct amount based on the number of keys. The
93
+ # parameters are filled later when executing the query. This is done through Active Record
94
+ # to ensure the field and table names are properly quoted and escaped based on the used database adapter.
95
+
96
+ # For example: The query for 4 keys will be transformed from:
97
+ # > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (1111, 2222)
98
+ # into:
99
+ # > SELECT "key", "value" FROM "solid_cache_entries" WHERE "key_hash" IN (?, ?, ?, ?)
87
100
  def select_sql(keys)
88
- @get_sql ||= {}
89
- @get_sql[keys.count] ||= \
90
- where(key_hash: [ "1111", "2222" ])
101
+ @select_sql ||= {}
102
+ @select_sql[keys.count] ||= \
103
+ where(key_hash: [ 1111, 2222 ])
91
104
  .select(:key, :value)
92
105
  .to_sql
93
- .gsub("1111, 2222", (["?"] * keys.count).join(", "))
106
+ .gsub("1111, 2222", Array.new(keys.count, "?").join(", "))
94
107
  end
95
108
 
96
109
  def key_hash_for(key)
@@ -7,10 +7,8 @@ class SolidCache::InstallGenerator < Rails::Generators::Base
7
7
  desc: "Skip migrations"
8
8
 
9
9
  def add_rails_cache
10
- %w[development test production].each do |env_name|
11
- if (env_config = Pathname(destination_root).join("config/environments/#{env_name}.rb")).exist?
12
- gsub_file env_config, /(# )?config\.cache_store = (:(?!null_store).*)/, "config.cache_store = :solid_cache_store"
13
- end
10
+ if (env_config = Pathname(destination_root).join("config/environments/production.rb")).exist?
11
+ gsub_file env_config, /(# )?config\.cache_store = (:.*)/, "config.cache_store = :solid_cache_store"
14
12
  end
15
13
  end
16
14
 
@@ -1,7 +1,6 @@
1
1
  default: &default
2
2
  database: <%= ENV.fetch("DATABASE", "cache") %>
3
3
  store_options:
4
- max_age: <%%= 1.week.to_i %>
5
4
  max_size: <%%= 256.megabytes %>
6
5
  namespace: <%%= Rails.env %>
7
6
 
@@ -37,9 +37,9 @@ module SolidCache
37
37
  end
38
38
 
39
39
  config.after_initialize do
40
- if SolidCache.configuration.encrypt? && SolidCache::Record.connection.adapter_name == "PostgreSQL"
40
+ if SolidCache.configuration.encrypt? && Record.connection.adapter_name == "PostgreSQL" && Rails::VERSION::MAJOR <= 7
41
41
  raise \
42
- "Cannot enable encryption for Solid Cache: Active Record Encryption does not currently support " \
42
+ "Cannot enable encryption for Solid Cache: in Rails 7, Active Record Encryption does not support " \
43
43
  "encrypting binary columns on PostgreSQL"
44
44
  end
45
45
  end
@@ -15,11 +15,21 @@ module SolidCache
15
15
  end
16
16
 
17
17
  def increment(name, amount = 1, options = nil)
18
- adjust(name, amount, options)
18
+ options = merged_options(options)
19
+ key = normalize_key(name, options)
20
+
21
+ instrument :increment, key, amount: amount do
22
+ adjust(name, amount, options)
23
+ end
19
24
  end
20
25
 
21
26
  def decrement(name, amount = 1, options = nil)
22
- adjust(name, -amount, options)
27
+ options = merged_options(options)
28
+ key = normalize_key(name, options)
29
+
30
+ instrument :decrement, key, amount: amount do
31
+ adjust(name, -amount, options)
32
+ end
23
33
  end
24
34
 
25
35
  def cleanup(options = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCache
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donal McBreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-21 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord