Krug.DistributedMnesiaSqlCache (Krug v1.1.20) View Source
Utilitary module to handle Erlang Mnesia Database. Mnesia Database has single instance mode and also distributed mode that is purpose of this module. Single instance way don't allow us to improve horizontal scalability when we need.
Link to this section Summary
Functions
Provides cache functionality to clear SQL queries result. Return true or false.
Almost the same that "init_cluster". The diference is that cluster_ips will be calculated to be all range of machine local network according the network mask range (/16 or /24).
Start the mnesia cluster. To be used on application start.
Provides cache functionality to load SQL queries result. Return the cache result or nil.
Provides cache functionality to store SQL queries result. Return true or false.
Link to this section Functions
Provides cache functionality to clear SQL queries result. Return true or false.
Requires mnesia already be started.
If you wish you application be able to scalabity then should be used
init_cluster(cluster_name,cluster_ips,ips_separator,disc_copies,table_names)
function on application startup.
init_auto_cluster(cluster_name, cluster_cookie, disc_copies \\ false, table_names \\ [], connection_timeout \\ nil)
View SourceAlmost the same that "init_cluster". The diference is that cluster_ips will be calculated to be all range of machine local network according the network mask range (/16 or /24).
init_cluster(cluster_name, cluster_cookie, cluster_ips, ips_separator \\ "|", disc_copies \\ false, table_names \\ [], connection_timeout \\ nil)
View SourceStart the mnesia cluster. To be used on application start.
Example
defmodule <Your_App_Main_Module_Name>.Application do
@moduledoc false
use Application
alias Krug.DistributedMnesiaSqlCache
def start(_type, _args) do
Supervisor.start_link(children(), opts())
end
defp children() do
[
...
<Your_App_Main_Module_Name>.DistributedMnesiaSqlCacheTaskStarter, # calls Krug.DistributedMnesiaSqlCache.init_cluster(...)
...
]
end
defp opts() do
[strategy: :one_for_one, name: <Your_App_Main_Module_Name>.Supervisor]
end
end
defmodule <Your_App_Main_Module_Name>.DistributedMnesiaSqlCacheConfigTaskStarter do
def child_spec(opts) do
%{id: __MODULE__,start: {__MODULE__, :start_link, [opts]}}
end
def start_link(opts) do
Supervisor.start_link([{<Your_App_Main_Module_Name>.DistributedMnesiaSqlCacheConfigTask,opts}], strategy: :one_for_one)
end
end
defmodule <Your_App_Main_Module_Name>.DistributedMnesiaSqlCacheConfigTask do
use Task
alias Krug.DistributedMnesiaSqlCache
def start_link(opts) do
Task.start_link(__MODULE__, :run, [opts])
end
def run(_opts) do
cluster_cookie = "echo"
cluster_name = "echo"
cluster_ips = "192.168.1.12X "
ips_separator = "X"
table_names = [
:users,
:log,
:other_table
]
cluster_name
|> DistributedMnesiaSqlCache.init_cluster(cluster_cookie,cluster_ips,ips_separator,true,table_names)
end
end
Provides cache functionality to load SQL queries result. Return the cache result or nil.
Requires mnesia already be started.
If you wish you application be able to scalabity then should be used
init_cluster(cluster_name,cluster_ips,ips_separator,disc_copies,table_names)
function on application startup.
Provides cache functionality to store SQL queries result. Return true or false.
Requires mnesia already be started.
If you wish you application be able to scalabity then should be used
init_cluster(cluster_name,cluster_ips,ips_separator,disc_copies,table_names)
function on application startup.