Module depcache

In-memory caching server with dependency checks and local in process memoization of lookups.

Copyright © 2009-2016 Marc Worrell, Arjan Scherpenisse

Behaviours: gen_server.

Authors: Marc Worrell (marc@worrell.nl).

Description

In-memory caching server with dependency checks and local in process memoization of lookups.

Data Types

depcache_server()

depcache_server() = pid() | atom()

dependencies()

dependencies() = [key()]

key()

key() = any()

max_age_secs()

max_age_secs() = non_neg_integer()

memo_fun()

memo_fun() = function() | mfa() | {module(), atom()}

Function Index

cleanup/1Cleanup process for the depcache.
cleanup/5
code_change/3
flush/1Flush all keys from the caches.
flush/2Flush the key and all keys depending on the key.
flush_process_dict/0Flush all items memoized in the process dictionary.
get/2Fetch the key from the cache, return the data or an undefined if not found (or not valid).
get/3Fetch the key from the cache, return the data or an undefined if not found (or not valid).
get_subkey/3Fetch the key from the cache, return the data or an undefined if not found (or not valid).
get_wait/2Fetch the key from the cache, when the key does not exist then lock the entry and let the calling process insert the value.
handle_call/3Return the ets tables used by the cache.
handle_cast/2
handle_info/2
in_process/1Enable or disable the in-process caching using the process dictionary.
in_process_server/1Check if we use a local process dict cache.
init/1Initialize the depcache.
memo/2
memo/3
memo/4
memo/5
set/3Add the key to the depcache, hold it for 3600 seconds and no dependencies.
set/4Add the key to the depcache, hold it for MaxAge seconds and no dependencies.
set/5Add the key to the depcache, hold it for MaxAge seconds and check the dependencies.
size/1Return the total memory size of all stored terms.
start_link/1Start a depcache process.
start_link/2Start a named depcache process.
terminate/2

Function Details

cleanup/1

cleanup(Cleanup_state) -> any()

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/5

cleanup(Cleanup_state, SlotNr, Now, Mode, Ct) -> any()

code_change/3

code_change(OldVersion, State, Extra) -> any()

flush/1

flush(Server::depcache_server()) -> ok

Flush all keys from the caches

flush/2

flush(Key::key(), Server::depcache_server()) -> ok

Flush the key and all keys depending on the key

flush_process_dict/0

flush_process_dict() -> any()

Flush all items memoized in the process dictionary.

get/2

get(Key::key(), Server::depcache_server()) -> {ok, any()} | undefined

Fetch the key from the cache, return the data or an undefined if not found (or not valid)

get/3

get(Key::key(), SubKey::key(), Server::depcache_server()) -> {ok, any()} | undefined

Fetch the key from the cache, return the data or an undefined if not found (or not valid)

get_subkey/3

get_subkey(Key::key(), SubKey::key(), Server::depcache_server()) -> {ok, any()} | undefined

Fetch the key from the cache, return the data or an undefined if not found (or not valid)

get_wait/2

get_wait(Key::key(), Server::depcache_server()) -> {ok, any()} | undefined

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.

handle_call/3

handle_call(X1, From, State) -> any()

Return the ets tables used by the cache

handle_cast/2

handle_cast(Msg, State) -> any()

handle_info/2

handle_info(Msg, State) -> any()

in_process/1

in_process(X1::boolean()) -> ok

Enable or disable the in-process caching using the process dictionary

in_process_server/1

in_process_server(Server::depcache_server()) -> boolean()

Check if we use a local process dict cache.

init/1

init(Config) -> {ok, State}

Initialize the depcache. Creates ets tables for the deps, meta and data. Spawns garbage collector.

memo/2

memo(Fun::memo_fun(), Server::depcache_server()) -> any()

memo/3

memo(Fun::memo_fun(), MaxAge::max_age_secs() | key(), Server::depcache_server()) -> any()

memo/4

memo(Fun::memo_fun(), Key::max_age_secs(), MaxAge::key(), Server::depcache_server()) -> any()

memo/5

memo(Fun::memo_fun(), Key::max_age_secs(), MaxAge::key(), Dep::dependencies(), Server::depcache_server()) -> any()

set/3

set(Key::key(), Data::any(), Server::depcache_server()) -> ok

Add the key to the depcache, hold it for 3600 seconds and no dependencies

set/4

set(Key::key(), Data::any(), MaxAge::max_age_secs(), Server::depcache_server()) -> ok

Add the key to the depcache, hold it for MaxAge seconds and no dependencies

set/5

set(Key::key(), Data::any(), MaxAge::max_age_secs(), Depend::dependencies(), Server::depcache_server()) -> ok

Add the key to the depcache, hold it for MaxAge seconds and check the dependencies

size/1

size(Server::depcache_server()) -> non_neg_integer()

Return the total memory size of all stored terms

start_link/1

start_link(Config::proplists:proplist()) -> {ok, pid()} | ignore | {error, term()}

Start a depcache process.

For Config, you can pass: {callback, {Module, Function, Arguments}}: depcache event callback {memory_max, MaxMemoryInMB}: number of MB to limit depcache size at.

start_link/2

start_link(Name::atom(), Config::proplists:proplist()) -> {ok, pid()} | ignore | {error, term()}

Start a named depcache process.

For Config, you can pass: {callback, {Module, Function, Arguments}}: depcache event callback {memory_max, MaxMemoryInMB}: number of MB to limit depcache size at.

terminate/2

terminate(Reason, State) -> any()


Generated by EDoc