Copyright © 2009-2020 Marc Worrell, Arjan Scherpenisse
Behaviours: gen_server.
Authors: Arjan Scherpenisse.
Depcache API
flush/1, flush/2, get/2, get/3, get_subkey/3,
get_wait/2, set/3, set/4, set/5, size/1
memo/2, memo/3, memo/4, memo/5
flush_process_dict/0, in_process/1, in_process_server/1
cleanup/1, cleanup/5
callback() = mfargs()
cleanup_state() = #cleanup_state{pid = pid(), tables = tables(), name = atom(), memory_max = non_neg_integer(), callback = callback() | undefined}
config() = config_map() | config_proplist()
config_map() = #{memory_max => non_neg_integer() | undefined, callback => callback() | undefined}
config_proplist() = [{memory_max, non_neg_integer | undefined} | {callback, callback() | undefined}]
depcache_server() = pid() | atom()
dependencies() = [key()]
key() = any()
max_age_secs() = sec()
memo_fun() = function() | mfargs() | {module(), atom()}
mfargs() = {module(), atom(), list()}
sec() = non_neg_integer()
tables() = #tables{meta_table = ets:tab(), deps_table = ets:tab(), data_table = ets:tab()}
| cleanup/1 | Cleanup process for the depcache. |
| cleanup/5 | Cleanup process for the depcache. |
| flush/1 | Flush all keys from the caches. |
| flush/2 | Flush the key and all keys depending on that key. |
| flush_process_dict/0 | Flush all items memoized in the process dictionary. |
| get/2 | Fetch the key from the cache, return the data or an undefined if not found (or not valid). |
| get/3 | Fetch the key from the cache, return the data or an undefined if not found (or not valid). |
| get_subkey/3 | Fetch the key from the cache, return the data or an undefined if not found (or not valid). |
| get_wait/2 | Fetch the key from the cache, when the key does not exist then lock the entry and let the calling process insert the value. |
| in_process/1 | Enable or disable the in-process caching using the process dictionary. |
| in_process_server/1 | Check if we use a local process dict cache. |
| memo/2 | Cache the result of the function for an hour. |
| memo/3 | If Fun is a function then cache for an hour given the key. |
| memo/4 | Cache the result of the function as Key for MaxAge seconds. |
| memo/5 | Cache the result of the function as Key for MaxAge seconds, flush
the cached result if any of the dependencies is changed. |
| set/3 | Add the key to the depcache, hold it for 3600 seconds and no dependencies. |
| set/4 | Add the key to the depcache, hold it for MaxAge seconds and no dependencies. |
| set/5 | Add the key to the depcache, hold it for MaxAge seconds and check the dependencies. |
| size/1 | Return the total memory size of all stored terms. |
| start_link/1 | Start a depcache process. |
| start_link/2 | Start a named depcache process. |
Equivalent to cleanup(CleanUp_state, SlotNr, Now, Mode, Ct).
Cleanup process for the depcache. Periodically checks a batch of depcache items for their validity. Asks the depcache server to delete invalidated items. When the load of the data table is too high then This cleanup process starts to delete random entries. By using a random delete we don't need to keep a LRU list, which is a bit expensive.
cleanup(State, SlotNr, Now, Mode, Ct) -> Result
State = cleanup_state()SlotNr = '$end_of_table' | non_neg_integer()Now = sec()Mode = normal | cache_fullCt = integer()Result = no_return()
Cleanup process for the depcache. Periodically checks a batch of depcache items for their validity. Asks the depcache server to delete invalidated items. When the load of the data table is too high then This cleanup process starts to delete random entries. By using a random delete we don't need to keep a LRU list, which is a bit expensive.
Flush all keys from the caches
See also:
gen_server:call/2.
Flush the key and all keys depending on that key
See also:
gen_server:call/2.
flush_process_dict() -> Result
Result = ok
Flush all items memoized in the process dictionary.
Fetch the key from the cache, return the data or an undefined if not found (or not valid).
See also:
gen_server:call/2.
get(Key, SubKey, Server) -> Result
Key = key()SubKey = key()Server = depcache_server()Result = {ok, any()} | undefined
Fetch the key from the cache, return the data or an undefined if not found (or not valid)
See also:
gen_server:call/2.
get_subkey(Key, SubKey, Server) -> Result
Key = key()SubKey = key()Server = depcache_server()Result = {ok, any()} | undefined
Fetch the key from the cache, return the data or an undefined if not found (or not valid)
See also:
gen_server:call/2.
get_wait(Key, Server) -> Result
Key = key()Server = depcache_server()Result = {ok, any()} | undefined | {throw, term()}
Fetch the key from the cache, when the key does not exist then lock the entry and let
the calling process insert the value. All other processes requesting the key will wait till
the key is updated and receive the key's new value.
See also:
gen_server:call/3.
in_process(IsChaching) -> Result
IsChaching = undefined | boolean()Result = undefined | boolean()
Enable or disable the in-process caching using the process dictionary
Check if we use a local process dict cache.
memo(Fun, Server) -> Result
Fun = memo_fun()Server = depcache_server()Result = any()Fun: a function for producing a value
returns: cached value
Cache the result of the function for an hour.
memo(Fun, MaxAge_Key, Server) -> Result
Fun = memo_fun()MaxAge_Key = MaxAge | KeyMaxAge = max_age_secs()Key = key()Server = depcache_server()Result = any()Fun: a function for producing a value1
returns: cached value
If Fun is a function then cache for an hour given the key. If
Fun is a {M,F,A} tuple then derive the key from the tuple and
cache for MaxAge seconds.
memo(Fun, Key, MaxAge, Server) -> Result
Fun = memo_fun()Key = key()MaxAge = max_age_secs()Server = depcache_server()Result = any()
returns: cached value
Equivalent to memo(Fun, Key, MaxAge, [], Server).
Cache the result of the function as Key for MaxAge seconds.
memo(Fun, Key, MaxAge, Dep, Server) -> Result
Fun = memo_fun()Key = undefined | key()MaxAge = max_age_secs()Dep = dependencies()Server = depcache_server()Result = any()
returns: cached value
Cache the result of the function as Key for MaxAge seconds, flush
the cached result if any of the dependencies is changed.
Equivalent to set(Key, Data, 3600, [], Server).
Add the key to the depcache, hold it for 3600 seconds and no dependencies.
set(Key, Data, MaxAge, Server) -> Result
Key = key()Data = any()MaxAge = max_age_secs()Server = depcache_server()Result = ok
Equivalent to set(Key, Data, MaxAge, [], Server).
Add the key to the depcache, hold it for MaxAge seconds and no dependencies.
set(Key, Data, MaxAge, Depend, Server) -> Result
Key = key()Data = any()MaxAge = max_age_secs()Depend = dependencies()Server = depcache_server()Result = okMaxAge: maximum lifetime of an element in the cache
Depend: list of subkeys
See also:
gen_server:call/2.
Add the key to the depcache, hold it for MaxAge seconds and check the dependencies.
Return the total memory size of all stored terms
start_link(Config) -> Result
Config = config()Result = {ok, pid()} | ignore | {error, term()}Config: configuration options
returns: Result of starting gen_server item.
Start a depcache process.
See also:
gen_server:start_link/3.
callback => {Module, Function, Arguments}memory_max => MaxMemoryInMBstart_link(Name, Config) -> Result
Name = atom()Config = config()Result = {ok, pid()} | ignore | {error, term()}Name: of process
Config: configuration options
returns: Result of starting gen_server item.
Start a named depcache process.
See also:
gen_server:start_link/4.
callback => {Module, Function, Arguments}memory_max => MaxMemoryInMBGenerated by EDoc