Dalli is a high performance pure Ruby client for accessing memcached servers.
Dalli supports:
The name is a variant of Salvador Dali for his famous painting The Persistence of Memory.
Dalli is tested against both the minimum supported memcached version and the
latest release. Earlier 1.6.x servers are not supported: the meta protocol
rejects unknown flags outright, so features added after a server's release fail
with CLIENT_ERROR invalid flag rather than degrading.
Use namespaces to partition your cache and avoid key collisions between different applications or environments:
# All keys will be prefixed with "myapp:"
Dalli::Client.new('localhost:11211', namespace: 'myapp')
# Dynamic namespace using a Proc (evaluated on each operation)
Dalli::Client.new('localhost:11211', namespace: -> { "tenant:#{Thread.current[:tenant_id]}" })
By default, the namespace and key are joined with a colon (:). You can customize this with the namespace_separator option:
# Keys will be prefixed with "myapp/" instead of "myapp:"
Dalli::Client.new('localhost:11211', namespace: 'myapp', namespace_separator: '/')
The separator must be a single non-alphanumeric character. Valid examples: :, /, |, ., -, _, #
By default, Dalli uses Ruby's Marshal for serialization. Deserializing untrusted data with Marshal can lead to remote code execution. If you cache user-controlled data, consider using a safer serializer:
Dalli::Client.new('localhost:11211', serializer: JSON)
See the 5.0-Upgrade.md guide for upgrade information.
Dalli automatically instruments operations with OpenTelemetry when the SDK is present. No configuration is required - just add the OpenTelemetry gems to your application:
# Gemfile
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp' # or your preferred exporter
When OpenTelemetry is loaded, Dalli creates spans for:
get, set, delete, add, replace, incr, decr, etc.get_multi, set_multi, delete_multiget_with_metadata, fetch_with_lockAll spans include:
db.system: memcacheddb.operation: The operation name (e.g., get, set_multi)Single-key operations also include:
server.address: The memcached server that handled the request (e.g., localhost:11211)Multi-key operations include cache efficiency metrics:
db.memcached.key_count: Number of keys in the requestdb.memcached.hit_count: Number of keys found (for get_multi)db.memcached.miss_count: Number of keys not found (for get_multi)Exceptions are automatically recorded on spans with error status. When an operation fails:
span.record_exception(e)To disable instrumentation at runtime (e.g., in tests or specific environments):
Dalli::Instrumentation.disable!
You can also assign a custom tracer directly:
Dalli::Instrumentation.tracer = my_custom_tracer
When OpenTelemetry is not present, there is zero overhead - the tracing code checks once at startup and bypasses all instrumentation logic entirely when the SDK is not loaded.

Dalli::Client APIAfter checking out the repo, run bin/setup to install dependencies. You can run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Please see CONTRIBUTING.md for guidelines on how to contribute, including our policy on AI-authored contributions.
Dalli would not exist in its current form without the contributions of many people. But special thanks go to several individuals and organizations:
Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
(top 30 of 154)
Ruby
98.4%
Shell
1.5%
Dalli is a high performance pure Ruby client for accessing memcached servers.
Dalli supports:
The name is a variant of Salvador Dali for his famous painting The Persistence of Memory.
Dalli is tested against both the minimum supported memcached version and the
latest release. Earlier 1.6.x servers are not supported: the meta protocol
rejects unknown flags outright, so features added after a server's release fail
with CLIENT_ERROR invalid flag rather than degrading.
Use namespaces to partition your cache and avoid key collisions between different applications or environments:
# All keys will be prefixed with "myapp:"
Dalli::Client.new('localhost:11211', namespace: 'myapp')
# Dynamic namespace using a Proc (evaluated on each operation)
Dalli::Client.new('localhost:11211', namespace: -> { "tenant:#{Thread.current[:tenant_id]}" })
By default, the namespace and key are joined with a colon (:). You can customize this with the namespace_separator option:
# Keys will be prefixed with "myapp/" instead of "myapp:"
Dalli::Client.new('localhost:11211', namespace: 'myapp', namespace_separator: '/')
The separator must be a single non-alphanumeric character. Valid examples: :, /, |, ., -, _, #
By default, Dalli uses Ruby's Marshal for serialization. Deserializing untrusted data with Marshal can lead to remote code execution. If you cache user-controlled data, consider using a safer serializer:
Dalli::Client.new('localhost:11211', serializer: JSON)
See the 5.0-Upgrade.md guide for upgrade information.
Dalli automatically instruments operations with OpenTelemetry when the SDK is present. No configuration is required - just add the OpenTelemetry gems to your application:
# Gemfile
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp' # or your preferred exporter
When OpenTelemetry is loaded, Dalli creates spans for:
get, set, delete, add, replace, incr, decr, etc.get_multi, set_multi, delete_multiget_with_metadata, fetch_with_lockAll spans include:
db.system: memcacheddb.operation: The operation name (e.g., get, set_multi)Single-key operations also include:
server.address: The memcached server that handled the request (e.g., localhost:11211)Multi-key operations include cache efficiency metrics:
db.memcached.key_count: Number of keys in the requestdb.memcached.hit_count: Number of keys found (for get_multi)db.memcached.miss_count: Number of keys not found (for get_multi)Exceptions are automatically recorded on spans with error status. When an operation fails:
span.record_exception(e)To disable instrumentation at runtime (e.g., in tests or specific environments):
Dalli::Instrumentation.disable!
You can also assign a custom tracer directly:
Dalli::Instrumentation.tracer = my_custom_tracer
When OpenTelemetry is not present, there is zero overhead - the tracing code checks once at startup and bypasses all instrumentation logic entirely when the SDK is not loaded.

Dalli::Client APIAfter checking out the repo, run bin/setup to install dependencies. You can run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Please see CONTRIBUTING.md for guidelines on how to contribute, including our policy on AI-authored contributions.
Dalli would not exist in its current form without the contributions of many people. But special thanks go to several individuals and organizations:
Copyright (c) Mike Perham, Peter M. Goldstein. See LICENSE for details.
(top 30 of 154)
Ruby
98.4%
Shell
1.5%