Skip to content

Configure RedisMemo

Donald Dong edited this page Jun 3, 2021 · 6 revisions

A Real Example

https://github.com/chanzuckerberg/redis-memo/blob/main/docs/examples/config.rb

Options

You can configure and set various RedisMemo options in your initializer config/initializers/redis_memo.rb:

RedisMemo.configure do |config|

  config.expires_in = 3.hours
  config.global_cache_key_version = SecureRandom.uuid
  ...
end

See https://www.rubydoc.info/gems/redis-memo/1.0.0/RedisMemo/Options for a full list of configurable options.

Cache Sample Validation

RedisMemo has built-in cache sampling logic. An error reporter will be invoked if some methods have incorrect dependencies that cause the cache results to be out of date.

We highly recommend sampling at least 1% of the cached methods in production. When rolling out a new cached code path, one could start with a 100% cache sample rate until they feel confident enough to reduce the sample rate.

You can configure the cache sample validation percentage both globally or in inline method:

  1. To specify global validation percentage:
RedisMemo.configure do |config|
  config.cache_validation_sample_percentage = 100
  ...
end
  1. To specify validation percentage in inline method:
memoize_method :load, cache_validation_sample_percentage: 100

Kill switches

Cached queries can be disabled per model by setting an ENV variable REDIS_MEMO_DISABLE_<table name>. RedisMemo can be turned off globally when REDIS_MEMO_DISABLE_ALL is set to true.