modglobal v0.2.2 Modglobal View Source

Modglobal provides a simple key-value store that is unique per module. It is useful when you would otherwise need a GenServer to hold onto some state

Setup

For each module you need globals, add use Modglobal.

Usage

YourModule.set_global(key, value) YourModule.get_global(key), etc.

If you would rather not use the *_global convenience functions, the regular API is also supported as follows:

Modglobal.get(__MODULE__, key)

Modglobal.set(__MODULE__, key, value), etc…

Link to this section Summary

Functions

Deletes a given key from the module, and returns the value deleted. If the key was not present, then nil is returned

See get/3, where the default value is populated to be nil

For a module, retrieves the value of the passed in key. If the key is not present, then the default value is returned

Returns true if the key is present in the global cache, false otherwise. Note that this just checks the presence of the keys, even falsey values will return true

Increments an integer by 1 atomically, and returns the previous value. The initial value is 0, if the key is not already set

Sets the value, overwriting if necessary, to the key for the given module

Link to this section Functions

Link to this function delete(module, key) View Source
delete(module(), any()) :: any()

Deletes a given key from the module, and returns the value deleted. If the key was not present, then nil is returned.

Link to this function get(module, key) View Source
get(module(), any()) :: any()

See get/3, where the default value is populated to be nil

Link to this function get(module, key, default) View Source
get(module(), any(), any()) :: any()

For a module, retrieves the value of the passed in key. If the key is not present, then the default value is returned

Link to this function has?(module, key) View Source
has?(module(), any()) :: boolean()

Returns true if the key is present in the global cache, false otherwise. Note that this just checks the presence of the keys, even falsey values will return true

Link to this function increment(module, key) View Source
increment(module(), any()) :: any()

Increments an integer by 1 atomically, and returns the previous value. The initial value is 0, if the key is not already set

Link to this function set(module, key, value) View Source
set(module(), any(), any()) :: nil

Sets the value, overwriting if necessary, to the key for the given module.