Skip to content

Conversation

@djmb
Copy link
Collaborator

@djmb djmb commented May 1, 2024

Allows you to enable encryption of cache values with:

# config/solid_cache.yml
production:
  encrypt: true

or

# application.rb
config.solid_cache.encrypt = true

Requires Active Record Encryption to be configured already.

Solid Cache by default uses a custom encryptor and message serializer that are optimised for it.

Firstly it disabled compression with the encryptor ActiveRecord::Encryption::Encryptor.new(compress: false) - the cache already compresses the data.

Secondly it uses ActiveRecord::Encryption::MessagePackMessageSerializer.new as the serializer. This serializer can only be used for binary columns, but can store about 40% more data than the standard serializer.

Or allow custom context properties to be set:

# application.rb
config.solid_cache.encryption_context_properties = {
  encryptor: ActiveRecord::Encryption::Encryptor.new,
  message_serializer: ActiveRecord::Encryption::MessageSerializer.new
}

@djmb djmb added the v1.0 label May 1, 2024
@djmb djmb force-pushed the encrypt branch 3 times, most recently from 75d8332 to c12f746 Compare August 13, 2024 14:42
djmb added 2 commits August 20, 2024 14:13
Allows you to enable encryption of cache values with:

```yaml
\# config/solid_cache.yml
production:
  encrypt: true
```
or
```ruby
\# application.rb
config.solid_cache.encrypt = true
```

Requires Active Record Encryption to be configured already.

Solid Cache by default uses a custom encryptor and message serializer
that are optimised for it.

Firstly it disabled compression with the encryptor
`ActiveRecord::Encryption::Encryptor.new(compress: false)` - the cache
already compresses the data.

Secondly it uses `ActiveRecord::Encryption::MessagePackMessageSerializer.new`
as the serializer. This serializer can only be used for binary columns,
but can store about 40% more data than the standard serializer.

Or allow custom context properties to be set:

```ruby
\# application.rb
config.solid_cache.encryption_context_properties = {
  encryptor: ActiveRecord::Encryption::Encryptor.new,
  message_serializer: ActiveRecord::Encryption::MessageSerializer.new
}
```
Add 170 bytes to the estimated size of each entry when encryption is
enabled. This assumes that the default context properties are used.
@djmb djmb force-pushed the encrypt branch 2 times, most recently from a51973a to 2133d72 Compare August 20, 2024 13:45
This will need to wait for Rails to support binary encrypted columns -
see rails/rails#52650.
@djmb djmb merged commit 94ffc03 into main Aug 20, 2024
@djmb djmb deleted the encrypt branch August 20, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants