Skip to content

respect dalli’s cache_nil setting#39702

Closed
ritikesh wants to merge 1 commit intorails:6-0-stablefrom
ritikesh:dalli_cache_nils
Closed

respect dalli’s cache_nil setting#39702
ritikesh wants to merge 1 commit intorails:6-0-stablefrom
ritikesh:dalli_cache_nils

Conversation

@ritikesh
Copy link
Contributor

@ritikesh ritikesh commented Jun 22, 2020

Summary

Dalli provides an option to cache_nils as a performance optimisation configuration - https://github.com/petergoldstein/dalli/#configuration -> cache_nils.

ActiveSupport::Cache::MemCacheStore should deserialize the cached nils and return nil instead of Dalli::Server::NOT_FOUND.

Other Information

# config/application.rb
config.cache_store = :mem_cache_store, { 
    servers: %w(memcached:11211),
    namespace: 'namespace',
    compress: true,
    cache_nils: true
}

$memcached = Dalli::Client.new(%w(memcached:11211), {
    namespace: 'namespace',
    compress: true,
    cache_nils: true
})

> $memcached.fetch(:a) { nil }
=> nil
> $memcached.fetch(:a) { 1 }
=> nil

> Rails.cache.fetch(:z) { nil }
=> #<Dalli::Server::NilObject:0x00007ff30da57028>
> Rails.cache.fetch(:z) { 1 }
=> #<Dalli::Server::NilObject:0x00007ff30da57028>

reproducible on both 6-0-stable and master branches.

@ritikesh ritikesh closed this Jun 30, 2020
@ritikesh ritikesh deleted the dalli_cache_nils branch June 30, 2020 16:17
@ritikesh
Copy link
Contributor Author

ritikesh commented Jun 30, 2020

It seems Rails.cache caches nil by default and has a skip_nil flag for those who don't want the behaviour. Fix was to stop passing cache_nils: true to Rails.cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant