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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +110 -106
  3. data/Rakefile +11 -2
  4. data/app/models/solid_cache/entry/encryption.rb +15 -0
  5. data/app/models/solid_cache/entry/size/estimate.rb +1 -1
  6. data/app/models/solid_cache/entry/size/moving_average_estimate.rb +2 -2
  7. data/app/models/solid_cache/entry.rb +47 -97
  8. data/db/migrate/20240820123641_create_solid_cache_entries.rb +29 -0
  9. data/lib/generators/solid_cache/install/templates/config/solid_cache.yml.tt +1 -1
  10. data/lib/solid_cache/configuration.rb +20 -2
  11. data/lib/solid_cache/connections/sharded.rb +3 -4
  12. data/lib/solid_cache/connections.rb +1 -6
  13. data/lib/solid_cache/engine.rb +10 -0
  14. data/lib/solid_cache/store/api.rb +17 -6
  15. data/lib/solid_cache/store/connections.rb +108 -0
  16. data/lib/solid_cache/store/entries.rb +9 -7
  17. data/lib/solid_cache/{cluster → store}/execution.rb +4 -4
  18. data/lib/solid_cache/{cluster → store}/expiry.rb +1 -1
  19. data/lib/solid_cache/{cluster → store}/stats.rb +2 -2
  20. data/lib/solid_cache/store.rb +1 -5
  21. data/lib/solid_cache/version.rb +1 -1
  22. metadata +15 -19
  23. data/db/migrate/20230724121448_create_solid_cache_entries.rb +0 -11
  24. data/db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb +0 -8
  25. data/db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb +0 -11
  26. data/db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb +0 -7
  27. data/lib/solid_cache/cluster/connections.rb +0 -55
  28. data/lib/solid_cache/cluster.rb +0 -18
  29. 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