solid_cache 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +110 -106
- data/Rakefile +11 -2
- data/app/models/solid_cache/entry/encryption.rb +15 -0
- data/app/models/solid_cache/entry/size/estimate.rb +1 -1
- data/app/models/solid_cache/entry/size/moving_average_estimate.rb +2 -2
- data/app/models/solid_cache/entry.rb +47 -97
- data/db/migrate/20240820123641_create_solid_cache_entries.rb +29 -0
- data/lib/generators/solid_cache/install/templates/config/solid_cache.yml.tt +1 -1
- data/lib/solid_cache/configuration.rb +20 -2
- data/lib/solid_cache/connections/sharded.rb +3 -4
- data/lib/solid_cache/connections.rb +1 -6
- data/lib/solid_cache/engine.rb +10 -0
- data/lib/solid_cache/store/api.rb +17 -6
- data/lib/solid_cache/store/connections.rb +108 -0
- data/lib/solid_cache/store/entries.rb +9 -7
- data/lib/solid_cache/{cluster → store}/execution.rb +4 -4
- data/lib/solid_cache/{cluster → store}/expiry.rb +1 -1
- data/lib/solid_cache/{cluster → store}/stats.rb +2 -2
- data/lib/solid_cache/store.rb +1 -5
- data/lib/solid_cache/version.rb +1 -1
- metadata +15 -19
- data/db/migrate/20230724121448_create_solid_cache_entries.rb +0 -11
- data/db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb +0 -8
- data/db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb +0 -11
- data/db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb +0 -7
- data/lib/solid_cache/cluster/connections.rb +0 -55
- data/lib/solid_cache/cluster.rb +0 -18
- data/lib/solid_cache/store/clusters.rb +0 -83
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SolidCache
|
4
|
-
class Store
|
5
|
-
module Clusters
|
6
|
-
attr_reader :primary_cluster, :clusters
|
7
|
-
|
8
|
-
def initialize(options = {})
|
9
|
-
super(options)
|
10
|
-
|
11
|
-
clusters_options = options.fetch(:clusters) { [ options.fetch(:cluster, {}) ] }
|
12
|
-
|
13
|
-
@clusters = clusters_options.map.with_index do |cluster_options, index|
|
14
|
-
Cluster.new(options.merge(cluster_options).merge(async_writes: index != 0, error_handler: error_handler))
|
15
|
-
end
|
16
|
-
|
17
|
-
@primary_cluster = clusters.first
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup!
|
21
|
-
clusters.each(&:setup!)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
def reading_key(key, failsafe:, failsafe_returning: nil, &block)
|
26
|
-
failsafe(failsafe, returning: failsafe_returning) do
|
27
|
-
primary_cluster.with_connection_for(key, &block)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def reading_keys(keys, failsafe:, failsafe_returning: nil)
|
32
|
-
connection_keys = primary_cluster.group_by_connection(keys)
|
33
|
-
|
34
|
-
connection_keys.map do |connection, keys|
|
35
|
-
failsafe(failsafe, returning: failsafe_returning) do
|
36
|
-
primary_cluster.with_connection(connection) do
|
37
|
-
yield keys
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
def writing_key(key, failsafe:, failsafe_returning: nil)
|
45
|
-
first_cluster_sync_rest_async do |cluster, async|
|
46
|
-
failsafe(failsafe, returning: failsafe_returning) do
|
47
|
-
cluster.with_connection_for(key, async: async) do
|
48
|
-
yield cluster
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def writing_keys(entries, failsafe:, failsafe_returning: nil)
|
55
|
-
first_cluster_sync_rest_async do |cluster, async|
|
56
|
-
connection_entries = cluster.group_by_connection(entries)
|
57
|
-
|
58
|
-
connection_entries.map do |connection, entries|
|
59
|
-
failsafe(failsafe, returning: failsafe_returning) do
|
60
|
-
cluster.with_connection(connection, async: async) do
|
61
|
-
yield cluster, entries
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def writing_all(failsafe:, failsafe_returning: nil, &block)
|
69
|
-
first_cluster_sync_rest_async do |cluster, async|
|
70
|
-
cluster.connection_names.map do |connection|
|
71
|
-
failsafe(failsafe, returning: failsafe_returning) do
|
72
|
-
cluster.with_connection(connection, async: async, &block)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end.first
|
76
|
-
end
|
77
|
-
|
78
|
-
def first_cluster_sync_rest_async
|
79
|
-
clusters.map.with_index { |cluster, index| yield cluster, index != 0 }.first
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|