Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encrypt cache values via Solid Cache config #174

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Encrypt cache values via Solid Cache config #174

wants to merge 2 commits into from

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
}

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
}
```
@djmb djmb added the v1.0 label May 1, 2024
Add 170 bytes to the estimated size of each entry when encryption is
enabled. This assumes that the default context properties are used.
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.

None yet

1 participant