GitPedia

Nebulex

In-memory and distributed caching toolkit for Elixir.

From elixir-nebulexΒ·Updated June 22, 2026Β·View on GitHubΒ·

**nebulex** is a In-memory and distributed caching toolkit for Elixir. The project is written primarily in Elixir, distributed under the MIT License license, first published in 2017. It has gained significant community traction with 1,394 stars and 80 forks on GitHub. Key topics include: cache, caching, declarative, distributed, ecto.

Latest release: v3.0.4
<picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/elixir-nebulex/nebulex/main/guides/images/nbx-logo-white.png" /> <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/elixir-nebulex/nebulex/main/guides/images/nbx-logo.png" /> <img src="https://raw.githubusercontent.com/elixir-nebulex/nebulex/main/guides/images/nbx-logo.png" alt="Nebulex logo" /> </picture>

In-memory and distributed caching toolkit for Elixir


CI
Codecov
Hex.pm
Documentation

πŸš€ About

Nebulex provides support for transparently adding caching to existing
Elixir applications. Like Ecto, the caching abstraction allows
consistent use of various caching solutions with minimal impact on your
code.

Nebulex's cache abstraction shields developers from directly interacting with
underlying caching implementations, such as Redis,
Memcached, or other Elixir cache implementations like
Cachex. It also provides out-of-the-box features including
declarative decorator-based caching,
cache usage patterns, and
distributed cache topologies,
among others.


[!NOTE]

This README refers to the main branch of Nebulex, not the latest released
version on Hex. Please refer to the getting started guide
and the official documentation for the latest stable release.


πŸ“– Usage

To use Nebulex, add both :nebulex and your chosen cache adapter as
dependencies in your mix.exs file.

For more information about available adapters, check out the
Nebulex adapters guide.

For example, to use the Generational Local Cache
(Nebulex.Adapters.Local adapter), add the following to your mix.exs:

elixir
def deps do [ {:nebulex, "~> 3.0"}, {:nebulex_local, "~> 3.0"}, # Generational local cache adapter {:decorator, "~> 1.4"}, # Required for caching decorators {:telemetry, "~> 1.3"} # Required for telemetry events ] end

To provide more flexibility and load only the needed dependencies, Nebulex makes
all dependencies optional, including the adapters. For example:

  • For enabling declarative decorator-based caching:
    Add :decorator to the dependency list (recommended).

  • For enabling Telemetry events: Add :telemetry to the dependency list
    (recommended). See the Info API guide for monitoring cache stats
    and metrics.

Then run mix deps.get in your shell to fetch the dependencies. If you want to
use another cache adapter, just choose the appropriate dependency from the table
above.

Finally, in your cache definition, you'll need to specify the adapter:
corresponding to the chosen dependency. For the local cache, it would be:

elixir
defmodule MyApp.Cache do use Nebulex.Cache, otp_app: :my_app, adapter: Nebulex.Adapters.Local end

Don't forget to add MyApp.Cache to your application's supervision tree:

elixir
def start(_type, _args) do children = [ MyApp.Cache ] # ... rest of your supervision tree

You're now ready to use the cache:

elixir
iex> MyApp.Cache.put("foo", "bar") :ok iex> MyApp.Cache.fetch("foo") {:ok, "bar"}

For more detailed information, see the
getting started guide and
online documentation.


⚑ Quick Start Example with Caching Decorators

This example demonstrates how to use Nebulex with Ecto and declarative caching:

elixir
# In config/config.exs config :my_app, MyApp.Cache, # Create new generation every 12 hours gc_interval: :timer.hours(12), # Max 1M entries max_size: 1_000_000, # Max 2GB of memory allocated_memory: 2_000_000_000, # Run size and memory checks every 10 seconds gc_memory_check_interval: :timer.seconds(10) # Cache definition defmodule MyApp.Cache do use Nebulex.Cache, otp_app: :my_app, adapter: Nebulex.Adapters.Local end # Ecto schema defmodule MyApp.Accounts.User do use Ecto.Schema schema "users" do field :username, :string field :password, :string field :role, :string end def changeset(user, attrs) do user |> cast(attrs, [:username, :password, :role]) |> validate_required([:username, :password, :role]) end end # Accounts context with caching defmodule MyApp.Accounts do use Nebulex.Caching, cache: MyApp.Cache alias MyApp.Accounts.User alias MyApp.Repo # Cache entries expire after 1 hour @ttl :timer.hours(1) @decorate cacheable(key: {User, id}, opts: [ttl: @ttl]) def get_user!(id) do Repo.get!(User, id) end @decorate cacheable(key: {User, username}, references: & &1.id) def get_user_by_username(username) do Repo.get_by(User, [username: username]) end @decorate cache_put( key: {User, user.id}, match: &__MODULE__.match_update/1, opts: [ttl: @ttl] ) def update_user(%User{} = user, attrs) do user |> User.changeset(attrs) |> Repo.update() end @decorate cache_evict(key: {User, user.id}) def delete_user(%User{} = user) do Repo.delete(user) end def create_user(attrs \\ %{}) do %User{} |> User.changeset(attrs) |> Repo.insert() end def match_update({:ok, value}), do: {true, value} def match_update({:error, _}), do: false end


πŸ§ͺ Testing

To run only the tests:

bash
$ mix test

Additionally, to run all Nebulex checks:

bash
$ mix test.ci

The mix test.ci command will run the tests, coverage, credo, dialyzer,
and more. This is the recommended way to test Nebulex.


πŸ“Š Benchmarks

Nebulex provides a set of basic benchmark tests using the library
benchee, located in the
benchmarks directory.

To run a benchmark test:

bash
$ mix bench

The benchmark uses the Nebulex.Adapters.Nil adapter; it is more focused on
measuring the Nebulex abstraction layer performance rather than a specific
adapter.


🀝 Contributing

Contributions to Nebulex are very welcome and appreciated!

Use the issue tracker
for bug reports or feature requests. Open a
pull request
when you're ready to contribute.

Please read CONTRIBUTING.md for the full contribution
workflow, PR expectations, commit message conventions, and validation steps.


Copyright (c) 2017, Carlos BolaΓ±os.

Nebulex source code is licensed under the MIT License.

Contributors

Showing top 12 contributors by commit count.

View all contributors on GitHub β†’

This article is auto-generated from elixir-nebulex/nebulex via the GitHub API.Last fetched: 6/24/2026