Nebulex v1.0.0-rc.3 Nebulex.Adapters.Local View Source
Adapter module for Local Generational Cache.
It uses ExShards as memory backend (ETS tables are used internally).
Features
- Support for generational cache – inspired by epocxy
- Support for Sharding – handled by ExShards.
- Support for garbage collection via
Nebulex.Adapters.Local.Generation - Support for transactions via Erlang global name registration facility
Options
These options should be set in the config file and require recompilation in order to make an effect.
:adapter- The adapter name, in this case,Nebulex.Adapters.Local.:n_shards- The number of partitions for each Cache generation table. Defaults to:erlang.system_info(:schedulers_online).:n_generations- Max number of Cache generations, defaults to2.:read_concurrency- Indicates whether the tables thatExShardscreates uses:read_concurrencyor not (default: true).:write_concurrency- Indicates whether the tables thatExShardscreates uses:write_concurrencyor not (default: true).:gc_interval- Interval time in seconds to garbage collection to run, delete the oldest generation and create a new one. If this option is not set, garbage collection is never executed, so new generations must be created explicitly, e.g.:MyCache.new_generation([]).
Example
Nebulex.Cache is the wrapper around the Cache. We can define a
local cache as follows:
defmodule MyApp.LocalCache do
use Nebulex.Cache, otp_app: :my_app, adapter: Nebulex.Adapters.Local
end
Where the configuration for the Cache must be in your application
environment, usually defined in your config/config.exs:
config :my_app, MyApp.LocalCache,
n_shards: 2,
gc_interval: 3600,
write_concurrency: true
For more information about the usage, check Nebulex.Cache.
Extended API
This adapter provides some additional functions to the Nebulex.Cache API.
Most of these functions are used internally by the adapter, but there is one
function which is indeed provided to be used from the Cache API, and it is
the function to create new generations: new_generation/1.
MyApp.LocalCache.new_generation
Other additional function that might be useful is: __metadata__,
which is used to retrieve the Cache Metadata.
MyApp.LocalCache.__metadata__
The rest of the functions as we mentioned before, are for internal use.