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 +4 -4
- data/Rakefile +1 -1
- data/app/models/solid_cache/entry.rb +18 -5
- data/lib/generators/solid_cache/install/install_generator.rb +2 -4
- data/lib/generators/solid_cache/install/templates/config/solid_cache.yml.tt +0 -1
- data/lib/solid_cache/engine.rb +2 -2
- data/lib/solid_cache/store/api.rb +12 -2
- data/lib/solid_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8807bd93a8e16495e40542655163d95bcfac3b9a0d96de0ccbea687899ba600
|
4
|
+
data.tar.gz: 15107cc9ed202a7c8cf01d962c7ec8182eed76c3677e86155f104fac07eae6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
@
|
89
|
-
@
|
90
|
-
where(key_hash: [
|
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", (
|
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
|
-
|
11
|
-
|
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
|
|
data/lib/solid_cache/engine.rb
CHANGED
@@ -37,9 +37,9 @@ module SolidCache
|
|
37
37
|
end
|
38
38
|
|
39
39
|
config.after_initialize do
|
40
|
-
if SolidCache.configuration.encrypt? &&
|
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
|
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
|
-
|
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
|
-
|
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)
|
data/lib/solid_cache/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|