Skip to content

Commit

Permalink
rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
skatkov committed Aug 25, 2023
1 parent 9490f7b commit 4ac715f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Tested with:

## Usage
Add a gem to your Gemfile:
`gem 'activesupport-cache-database'`
```gem 'activesupport-cache-database'```

Generate a migration file to create required table:
`rails generate cache:database:install`
```rails generate cache:database:install```

Make sure to read through migration file, before running a migration. You might want to tweak it to fit your usecase.

Expand Down
8 changes: 4 additions & 4 deletions lib/generators/cache/database/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require "rails/generators/active_record"
require 'rails/generators/active_record'

module Cache
module Database
module Generators
class InstallGenerator < Rails::Generators::Base
include ActiveRecord::Generators::Migration

source_root File.join(__dir__, "templates")
desc "Add migration for ActiveSupport::Cache::Database"
source_root File.join(__dir__, 'templates')
desc 'Add migration for ActiveSupport::Cache::Database'

def self.next_migration_number(path)
next_migration_number = current_migration_number(path) + 1
ActiveRecord::Migration.next_migration_number(next_migration_number)
end

def copy_migrations
migration_template "create_table_for_cache.rb", "db/migrate/create_cache_database.rb"
migration_template 'create_table_for_cache.rb', 'db/migrate/create_cache_database.rb'
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Migration < ::ActiveRecord::Migration[5.2]
class Migration < ActiveRecord::Migration[5.2]
def change
create_table :activesupport_cache_entries, primary_key: 'key', id: :binary, limit: 255 do |t|
t.binary :value, null: false
Expand All @@ -17,7 +17,9 @@ def change
add_index :activesupport_cache_entries, :version, where: 'version IS NOT NULL'
end

# In case, your using Postgres you might wanto to turn table to unlogged tables. This comes with 50% write performance improvement, but comes with multiple downsides you need to be aware off:
# if your using Postgres you might want to turn cache table into unlogged tables.
# This comes with 50% write performance improvement, but comes with multiple
# downsides you need to be aware off:
# - No validation, data will be lost in case of forced restart.
# - No replication to read replicas
#
Expand Down

0 comments on commit 4ac715f

Please sign in to comment.