All Projects → cabol → Nebulex

cabol / Nebulex

Licence: mit
In-memory and distributed caching toolkit for Elixir.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Nebulex

Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+212.24%)
Mutual labels:  cache, caching, distributed
Cachier
Persistent, stale-free, local and cross-machine caching for Python functions.
Stars: ✭ 359 (-45.77%)
Mutual labels:  cache, caching
Coherence
Oracle Coherence Community Edition
Stars: ✭ 328 (-50.45%)
Mutual labels:  caching, distributed
Wp Rocket
Performance optimization plugin for WordPress
Stars: ✭ 394 (-40.48%)
Mutual labels:  cache, caching
Scrapbook
PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
Stars: ✭ 279 (-57.85%)
Mutual labels:  cache, caching
Redisson
Redisson - Redis Java client with features of In-Memory Data Grid. Over 50 Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Publish / Subscribe, Bloom filter, Spring Cache, Tomcat, Scheduler, JCache API, Hibernate, MyBatis, RPC, local cache ...
Stars: ✭ 17,972 (+2614.8%)
Mutual labels:  cache, distributed
Memento
Memento is a development-only tool that caches HTTP calls once they have been executed.
Stars: ✭ 380 (-42.6%)
Mutual labels:  cache, caching
salad
Asynchronous Scala Redis Client supporting Sentinel and Redis Cluster
Stars: ✭ 14 (-97.89%)
Mutual labels:  caching, cache
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (-35.95%)
Mutual labels:  cache, caching
Libmc
Fast and light-weight memcached client for C++ / #python / #golang #libmc
Stars: ✭ 429 (-35.2%)
Mutual labels:  cache, caching
Hazelcast
Open-source distributed computation and storage platform
Stars: ✭ 4,662 (+604.23%)
Mutual labels:  caching, distributed
Circuits
circuits is a Lightweight Event driven and Asynchronous Application Framework for the Python Programming Language with a strong Component Architecture.
Stars: ✭ 256 (-61.33%)
Mutual labels:  framework, distributed
lambda-cache
Python utility for caching in Lambda Functions
Stars: ✭ 28 (-95.77%)
Mutual labels:  caching, cache
Cache
The Cache component provides an extended PSR-6 implementation for adding cache to your applications.
Stars: ✭ 3,606 (+444.71%)
Mutual labels:  cache, caching
transitory
In-memory cache with high hit rates via LFU eviction for Node and browsers. Supports time-based expiration, automatic loading and metrics.
Stars: ✭ 24 (-96.37%)
Mutual labels:  caching, cache
Transmittable Thread Local
📌 TransmittableThreadLocal (TTL), the missing Java™ std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
Stars: ✭ 4,678 (+606.65%)
Mutual labels:  framework, distributed
Cached
Rust cache structures and easy function memoization
Stars: ✭ 530 (-19.94%)
Mutual labels:  cache, caching
HAProxy-2-RPM-builder
Build latest HAProxy binary with prometheus metrics support
Stars: ✭ 28 (-95.77%)
Mutual labels:  caching, cache
Ccache.cmake
🚅 Compile faster with Ccache! A Ccache integration for CMake with Xcode support.
Stars: ✭ 24 (-96.37%)
Mutual labels:  caching, cache
Stackexchange.redis.extensions
Stars: ✭ 419 (-36.71%)
Mutual labels:  cache, caching

Nebulex 🌌

In-memory and distributed caching toolkit for Elixir.

CI Coverage Status Inline docs Hex Version Docs License

Nebulex provides support for transparently adding caching into an existing Elixir application. Similar to Ecto, the caching abstraction allows consistent use of various caching solutions with minimal impact on the code.

Nebulex cache abstraction shields developers from directly dealing with the underlying caching implementations, such as Redis, Memcached, or even other Elixir cache implementations like Cachex. Additionally, it provides totally out-of-box features such as cache usage patterns, declarative annotation-based caching, and distributed cache topologies, among others.

See the getting started guide and the online documentation for more information.

Usage

You need to add nebulex as a dependency to your mix.exs file. However, in the case you want to use an external (a non built-in adapter) cache adapter, you also have to add the proper dependency to your mix.exs file.

The supported caches and their adapters are:

Cache Nebulex Adapter Dependency
Generational Local Cache Nebulex.Adapters.Local Built-In
Partitioned Nebulex.Adapters.Partitioned Built-In
Replicated Nebulex.Adapters.Replicated Built-In
Multilevel Nebulex.Adapters.Multilevel Built-In
Nil (special adapter that disables the cache) Nebulex.Adapters.Nil Built-In
Cachex Nebulex.Adapters.Cachex nebulex_adapters_cachex
Redis NebulexRedisAdapter nebulex_redis_adapter

For example, if you want to use a built-in cache, add to your mix.exs file:

def deps do
  [
    {:nebulex, "~> 2.0"},
    {:shards, "~> 1.0"},     #=> When using :shards as backend
    {:decorator, "~> 1.3"},  #=> When using Caching Annotations
    {:telemetry, "~> 0.4"}   #=> When using the Telemetry events (Nebulex stats)
  ]
end

In order to give more flexibility and fetch only needed dependencies, Nebulex makes all dependencies optional. For example:

  • For intensive workloads, you may want to use :shards as the backend for the local adapter and having partitioned tables. In such a case, you have to add :shards to the dependency list.

  • For enabling the usage of declarative annotation-based caching via decorators, you have to add :decorator to the dependency list.

  • For enabling Telemetry events to be dispatched when using Nebulex stats, you have to add :telemetry to the dependency list. See telemetry guide.

  • If you are using an adapter different than the built-in ones (e.g: Cachex or Redis adapter), you have to add the adapter dependency too.

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

Finally, in the cache definition, you will need to specify the adapter: respective to the chosen dependency. For the local built-in cache it is:

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

Quickstart example

Assuming you are using Ecto and you want to use declarative caching:

# In the config/config.exs file
config :my_app, MyApp.PartitionedCache,
  primary: [
    gc_interval: :timer.hours(12),
    backend: :shards,
    partitions: 2
  ]

# Defining a Cache with a partitioned topology
defmodule MyApp.PartitionedCache do
  use Nebulex.Cache,
    otp_app: :my_app,
    adapter: Nebulex.Adapters.Partitioned,
    primary_storage_adapter: Nebulex.Adapters.Local
end

# Some 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

# The Accounts context
defmodule MyApp.Accounts do
  use Nebulex.Caching

  alias MyApp.Accounts.User
  alias MyApp.PartitionedCache, as: Cache
  alias MyApp.Repo

  @ttl :timer.hours(1)

  @decorate cacheable(cache: Cache, key: {User, id}, opts: [ttl: @ttl])
  def get_user!(id) do
    Repo.get!(User, id)
  end

  @decorate cacheable(cache: Cache, key: {User, username}, opts: [ttl: @ttl])
  def get_user_by_username(username) do
    Repo.get_by(User, [username: username])
  end

  @decorate cache_put(
              cache: Cache,
              keys: [{User, usr.id}, {User, usr.username}],
              match: &match_update/1
            )
  def update_user(%User{} = usr, attrs) do
    usr
    |> User.changeset(attrs)
    |> Repo.update()
  end

  defp match_update({:ok, usr}), do: {true, usr}
  defp match_update({:error, _}), do: false

  @decorate cache_evict(cache: Cache, keys: [{User, usr.id}, {User, usr.username}])
  def delete_user(%User{} = usr) do
    Repo.delete(usr)
  end

  def create_user(attrs \\ %{}) do
    %User{}
    |> User.changeset(attrs)
    |> Repo.insert()
  end
end

See more Nebulex examples.

Important links

Testing

Testing by default spawns nodes internally for distributed tests. To run tests that do not require clustering, exclude the clustered tag:

$ mix test --exclude clustered

If you have issues running the clustered tests try running:

$ epmd -daemon

before running the tests.

Benchmarks

Nebulex provides a set of basic benchmark tests using the library benchee, and they are located within the directory benchmarks.

To run a benchmark test you have to run:

$ MIX_ENV=test mix run benchmarks/{BENCH_TEST_FILE}

Where BENCH_TEST_FILE can be any of:

  • local_with_ets_bench.exs: benchmark for the local adapter using :ets backend.
  • local_with_shards_bench.exs: benchmark for the local adapter using :shards backend.
  • partitioned_bench.exs: benchmark for the partitioned adapter.

For example, for running the benchmark for the local adapter using :shards backend:

$ MIX_ENV=test mix run benchmarks/local_with_shards_bench.exs

Additionally, you can also run performance tests using :basho_bench. See nebulex_bench example for more information.

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 are ready to contribute.

When submitting a pull request you should not update the CHANGELOG.md, and also make sure you test your changes thoroughly, include unit tests alongside new or changed code.

Before to submit a PR it is highly recommended to run mix check and ensure all checks run successfully.

Copyright and License

Copyright (c) 2017, Carlos Bolaños.

Nebulex source code is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].