solid_cache 1.0.8 → 1.0.9

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: fbc53d2cf4cc3edfeb5292055f3e8bb9c0057e4e067bee764a4d88a62fbd8278
4
- data.tar.gz: e3e9eac0f9a24a26eb3e992b2d2cdd0037c5d9ca4c36ea7cf8751b257fdf152b
3
+ metadata.gz: 70875a0c2373759080034b37dec27820e3e524972088278b429b5972fce42f5c
4
+ data.tar.gz: 89651c75f6b9847e22ceafb6d07607c4caee58a5f937a8e0963f3478a93028dd
5
5
  SHA512:
6
- metadata.gz: 3e94a6318abc57922c7b98c34b4034a660c8f598a557f0fb38a95f313228e02ae437396d415fe7bb2ed8782a492274458f621e059f74ea75905fd91b2bdee155
7
- data.tar.gz: deebaed2b15b865e87aaf27ac521e0b85fb8ebffab19651dec622c6ad6008cb489ec1648059a26f7d870bf327b8295f70eb76651bb3465a5613a16c14b2901b8
6
+ metadata.gz: ff76d3100601e08fa7d16a5f2b0bd9c950f5702ca0bd33c489132b03fd246631c749b3ec049e9001de45d64d562868743b2380b067b5bfd79deda2ec62b9e877
7
+ data.tar.gz: dcccb3c5faf1911bc7c6c329f9279816520c783df9cac80c72f7b1a33532c667a0d4dc63a2edfd05f9682b0f005feb67afab1427ec178d7e886ed7fc0cdb86b7
data/README.md CHANGED
@@ -9,7 +9,13 @@ Solid Cache is configured by default in new Rails 8 applications. But if you're
9
9
  1. `bundle add solid_cache`
10
10
  2. `bin/rails solid_cache:install`
11
11
 
12
- This will configure Solid Cache as the production cache store, create `config/cache.yml`, and create `db/cache_schema.rb`.
12
+ This will configure Solid Cache as the production cache store and create `config/cache.yml`.
13
+
14
+ If your application uses `config.active_record.schema_format = :ruby` (the default), the installer creates `db/cache_schema.rb`.
15
+
16
+ If your application uses `config.active_record.schema_format = :sql`, the installer creates `db/cache_structure.sql` with the appropriate SQL for your database adapter (PostgreSQL, MySQL, or SQLite).
17
+
18
+ ### Configuring the cache database
13
19
 
14
20
  You will then have to add the configuration for the cache database in `config/database.yml`. If you're using sqlite, it'll look like this:
15
21
 
@@ -39,7 +45,9 @@ production:
39
45
  migrations_paths: db/cache_migrate
40
46
  ```
41
47
 
42
- Then run `db:prepare` in production to ensure the database is created and the schema is loaded.
48
+ ### Finalizing installation
49
+
50
+ After configuring `database.yml`, run `db:prepare` in production to ensure the cache database is created and the schema is loaded.
43
51
 
44
52
  ## Configuration
45
53
 
@@ -64,7 +72,7 @@ production: &production
64
72
  databases: [production_cache1, production_cache2]
65
73
  store_options:
66
74
  <<: *default_store_options
67
- max_entries: <%= 256.gigabytes %>
75
+ max_size: <%= 256.gigabytes %>
68
76
  ```
69
77
 
70
78
  For the full list of keys for `store_options` see [Cache configuration](#cache-configuration). Any options passed to the cache lookup will overwrite those specified here.
@@ -80,19 +88,32 @@ config.cache_store = :solid_cache_store
80
88
 
81
89
  You can set one of `database`, `databases` and `connects_to` in the config file. They will be used to configure the cache databases in `SolidCache::Record#connects_to`.
82
90
 
83
- Setting `database` to `cache_db` will configure with:
91
+ If `connects_to` is set, it will be passed directly.
84
92
 
85
- ```ruby
86
- SolidCache::Record.connects_to database: { writing: :cache_db }
87
- ```
93
+ Setting `database` is shorthand for connecting to a single database:
88
94
 
89
- Setting `databases` to `[cache_db, cache_db2]` is the equivalent of:
95
+ ```yaml
96
+ database: :cache_db
90
97
 
91
- ```ruby
92
- SolidCache::Record.connects_to shards: { cache_db1: { writing: :cache_db1 }, cache_db2: { writing: :cache_db2 } }
98
+ # equivalent to
99
+ connects_to:
100
+ database:
101
+ writing: :cache_db
93
102
  ```
94
103
 
95
- If `connects_to` is set, it will be passed directly.
104
+ And `databases` to `[cache_db, cache_db2]` configures multiple database shards:
105
+
106
+ ```yaml
107
+ databases: [cache_db, cache_db2]
108
+
109
+ # equivalent to
110
+ connects_to:
111
+ shards:
112
+ cache_db1:
113
+ writing: :cache_db1
114
+ cache_db2:
115
+ writing: :cache_db2
116
+ ```
96
117
 
97
118
  If none of these are set, Solid Cache will use the `ActiveRecord::Base` connection pool. This means that cache reads and writes will be part of any wrapping database transaction.
98
119
 
@@ -5,11 +5,54 @@ class SolidCache::InstallGenerator < Rails::Generators::Base
5
5
 
6
6
  def copy_files
7
7
  template "config/cache.yml"
8
- template "db/cache_schema.rb"
8
+
9
+ if Rails.application.config.active_record.schema_format == :sql
10
+ copy_sql_schema_for_adapter
11
+ else
12
+ template "db/cache_schema.rb"
13
+ end
9
14
  end
10
15
 
11
16
  def configure_cache_store_adapter
12
17
  gsub_file Pathname.new(destination_root).join("config/environments/production.rb"),
13
18
  /(# )?config\.cache_store = (:.*)/, "config.cache_store = :solid_cache_store"
14
19
  end
20
+
21
+ private
22
+ def copy_sql_schema_for_adapter
23
+ sql_file = sql_schema_file_for_adapter
24
+
25
+ if sql_file
26
+ copy_file sql_file, "db/cache_structure.sql"
27
+ else
28
+ raise_unsupported_adapter_error
29
+ end
30
+ end
31
+
32
+ def sql_schema_file_for_adapter
33
+ case ActiveRecord::Base.connection_db_config.adapter
34
+ when "postgresql"
35
+ "db/cache_structure.postgresql.sql"
36
+ when "mysql2", "trilogy"
37
+ "db/cache_structure.mysql.sql"
38
+ when "sqlite3"
39
+ "db/cache_structure.sqlite3.sql"
40
+ else
41
+ nil
42
+ end
43
+ end
44
+
45
+ def raise_unsupported_adapter_error
46
+ error_message = <<~ERROR
47
+
48
+ ERROR: Unsupported database adapter for SQL schema format: #{adapter.inspect}
49
+
50
+ SolidCache supports installing for the following Rails adapters with schema_format = :sql:
51
+ - PostgreSQL (postgresql)
52
+ - MySQL (mysql2, trilogy)
53
+ - SQLite (sqlite3)
54
+ ERROR
55
+
56
+ raise error_message
57
+ end
15
58
  end
@@ -1,4 +1,5 @@
1
1
  default: &default
2
+ database: <%= ENV.fetch("DATABASE", "cache") %>
2
3
  store_options:
3
4
  # Cap age of oldest cache entry to fulfill retention policies
4
5
  # max_age: <%%= 60.days.to_i %>
@@ -12,5 +13,4 @@ test:
12
13
  <<: *default
13
14
 
14
15
  production:
15
- database: <%= ENV.fetch("DATABASE", "cache") %>
16
16
  <<: *default
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  ActiveRecord::Schema[7.2].define(version: 1) do
4
2
  create_table "solid_cache_entries", force: :cascade do |t|
5
3
  t.binary "key", limit: 1024, null: false
@@ -0,0 +1,56 @@
1
+
2
+ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
3
+ /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
4
+ /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
5
+ /*!50503 SET NAMES utf8mb4 */;
6
+ /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
7
+ /*!40103 SET TIME_ZONE='+00:00' */;
8
+ /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
9
+ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
10
+ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
11
+ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
12
+ DROP TABLE IF EXISTS `ar_internal_metadata`;
13
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
14
+ /*!50503 SET character_set_client = utf8mb4 */;
15
+ CREATE TABLE `ar_internal_metadata` (
16
+ `key` varchar(255) NOT NULL,
17
+ `value` varchar(255) DEFAULT NULL,
18
+ `created_at` datetime(6) NOT NULL,
19
+ `updated_at` datetime(6) NOT NULL,
20
+ PRIMARY KEY (`key`)
21
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
22
+ /*!40101 SET character_set_client = @saved_cs_client */;
23
+ DROP TABLE IF EXISTS `schema_migrations`;
24
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
25
+ /*!50503 SET character_set_client = utf8mb4 */;
26
+ CREATE TABLE `schema_migrations` (
27
+ `version` varchar(255) NOT NULL,
28
+ PRIMARY KEY (`version`)
29
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
30
+ /*!40101 SET character_set_client = @saved_cs_client */;
31
+ DROP TABLE IF EXISTS `solid_cache_entries`;
32
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
33
+ /*!50503 SET character_set_client = utf8mb4 */;
34
+ CREATE TABLE `solid_cache_entries` (
35
+ `id` bigint NOT NULL AUTO_INCREMENT,
36
+ `key` varbinary(1024) NOT NULL,
37
+ `value` longblob NOT NULL,
38
+ `created_at` datetime(6) NOT NULL,
39
+ `key_hash` bigint NOT NULL,
40
+ `byte_size` int NOT NULL,
41
+ PRIMARY KEY (`id`),
42
+ UNIQUE KEY `index_solid_cache_entries_on_key_hash` (`key_hash`),
43
+ KEY `index_solid_cache_entries_on_byte_size` (`byte_size`),
44
+ KEY `index_solid_cache_entries_on_key_hash_and_byte_size` (`key_hash`,`byte_size`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
46
+ /*!40101 SET character_set_client = @saved_cs_client */;
47
+ /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
48
+
49
+ /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
50
+ /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
51
+ /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
52
+ /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
53
+ /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
54
+ /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
55
+ /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
56
+
@@ -0,0 +1,128 @@
1
+ SET statement_timeout = 0;
2
+ SET lock_timeout = 0;
3
+ SET idle_in_transaction_session_timeout = 0;
4
+ SET transaction_timeout = 0;
5
+ SET client_encoding = 'UTF8';
6
+ SET standard_conforming_strings = on;
7
+ SELECT pg_catalog.set_config('search_path', '', false);
8
+ SET check_function_bodies = false;
9
+ SET xmloption = content;
10
+ SET client_min_messages = warning;
11
+ SET row_security = off;
12
+
13
+ SET default_tablespace = '';
14
+
15
+ SET default_table_access_method = heap;
16
+
17
+ --
18
+ -- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
19
+ --
20
+
21
+ CREATE TABLE public.ar_internal_metadata (
22
+ key character varying NOT NULL,
23
+ value character varying,
24
+ created_at timestamp(6) without time zone NOT NULL,
25
+ updated_at timestamp(6) without time zone NOT NULL
26
+ );
27
+
28
+
29
+ --
30
+ -- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
31
+ --
32
+
33
+ CREATE TABLE public.schema_migrations (
34
+ version character varying NOT NULL
35
+ );
36
+
37
+
38
+ --
39
+ -- Name: solid_cache_entries; Type: TABLE; Schema: public; Owner: -
40
+ --
41
+
42
+ CREATE TABLE public.solid_cache_entries (
43
+ id bigint NOT NULL,
44
+ key bytea NOT NULL,
45
+ value bytea NOT NULL,
46
+ created_at timestamp(6) without time zone NOT NULL,
47
+ key_hash bigint NOT NULL,
48
+ byte_size integer NOT NULL
49
+ );
50
+
51
+
52
+ --
53
+ -- Name: solid_cache_entries_id_seq; Type: SEQUENCE; Schema: public; Owner: -
54
+ --
55
+
56
+ CREATE SEQUENCE public.solid_cache_entries_id_seq
57
+ START WITH 1
58
+ INCREMENT BY 1
59
+ NO MINVALUE
60
+ NO MAXVALUE
61
+ CACHE 1;
62
+
63
+
64
+ --
65
+ -- Name: solid_cache_entries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
66
+ --
67
+
68
+ ALTER SEQUENCE public.solid_cache_entries_id_seq OWNED BY public.solid_cache_entries.id;
69
+
70
+
71
+ --
72
+ -- Name: solid_cache_entries id; Type: DEFAULT; Schema: public; Owner: -
73
+ --
74
+
75
+ ALTER TABLE ONLY public.solid_cache_entries ALTER COLUMN id SET DEFAULT nextval('public.solid_cache_entries_id_seq'::regclass);
76
+
77
+
78
+ --
79
+ -- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
80
+ --
81
+
82
+ ALTER TABLE ONLY public.ar_internal_metadata
83
+ ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
84
+
85
+
86
+ --
87
+ -- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
88
+ --
89
+
90
+ ALTER TABLE ONLY public.schema_migrations
91
+ ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
92
+
93
+
94
+ --
95
+ -- Name: solid_cache_entries solid_cache_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
96
+ --
97
+
98
+ ALTER TABLE ONLY public.solid_cache_entries
99
+ ADD CONSTRAINT solid_cache_entries_pkey PRIMARY KEY (id);
100
+
101
+
102
+ --
103
+ -- Name: index_solid_cache_entries_on_byte_size; Type: INDEX; Schema: public; Owner: -
104
+ --
105
+
106
+ CREATE INDEX index_solid_cache_entries_on_byte_size ON public.solid_cache_entries USING btree (byte_size);
107
+
108
+
109
+ --
110
+ -- Name: index_solid_cache_entries_on_key_hash; Type: INDEX; Schema: public; Owner: -
111
+ --
112
+
113
+ CREATE UNIQUE INDEX index_solid_cache_entries_on_key_hash ON public.solid_cache_entries USING btree (key_hash);
114
+
115
+
116
+ --
117
+ -- Name: index_solid_cache_entries_on_key_hash_and_byte_size; Type: INDEX; Schema: public; Owner: -
118
+ --
119
+
120
+ CREATE INDEX index_solid_cache_entries_on_key_hash_and_byte_size ON public.solid_cache_entries USING btree (key_hash, byte_size);
121
+
122
+
123
+ --
124
+ -- PostgreSQL database dump complete
125
+ --
126
+
127
+ SET search_path TO "$user", public;
128
+
@@ -0,0 +1,6 @@
1
+ CREATE TABLE IF NOT EXISTS "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
2
+ CREATE TABLE IF NOT EXISTS "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
3
+ CREATE TABLE IF NOT EXISTS "solid_cache_entries" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "key" blob(1024) NOT NULL, "value" blob(536870912) NOT NULL, "created_at" datetime(6) NOT NULL, "key_hash" integer(8) NOT NULL, "byte_size" integer(4) NOT NULL);
4
+ CREATE INDEX "index_solid_cache_entries_on_byte_size" ON "solid_cache_entries" ("byte_size");
5
+ CREATE INDEX "index_solid_cache_entries_on_key_hash_and_byte_size" ON "solid_cache_entries" ("key_hash", "byte_size");
6
+ CREATE UNIQUE INDEX "index_solid_cache_entries_on_key_hash" ON "solid_cache_entries" ("key_hash");
@@ -37,7 +37,7 @@ module SolidCache
37
37
  when database
38
38
  { shards: { database.to_sym => { writing: database.to_sym } } }
39
39
  when databases
40
- { shards: databases.map(&:to_sym).index_with { |database| { writing: database } } }
40
+ { shards: Array(databases).map(&:to_sym).index_with { |database| { writing: database } } }
41
41
  when connects_to
42
42
  connects_to
43
43
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidCache
4
- VERSION = "1.0.8"
4
+ VERSION = "1.0.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donal McBreen
@@ -116,6 +116,9 @@ files:
116
116
  - lib/generators/solid_cache/install/install_generator.rb
117
117
  - lib/generators/solid_cache/install/templates/config/cache.yml.tt
118
118
  - lib/generators/solid_cache/install/templates/db/cache_schema.rb
119
+ - lib/generators/solid_cache/install/templates/db/cache_structure.mysql.sql
120
+ - lib/generators/solid_cache/install/templates/db/cache_structure.postgresql.sql
121
+ - lib/generators/solid_cache/install/templates/db/cache_structure.sqlite3.sql
119
122
  - lib/solid_cache.rb
120
123
  - lib/solid_cache/configuration.rb
121
124
  - lib/solid_cache/connections.rb