Module lru

Behaviours: gen_server.

Data Types

lru_option()

lru_option() = {evict_fun, function()} | {spawn_opt, list()}

Function Index

add/3adds a value to the cache.
contains/2check if the key is in the cache.
contains_or_add/3 checks if a key is in the cache (without updating the recent-ness or deleting it for being stale), if not, adds the value.
get/2lookup a key's value from the cache.
get/3lookup a key's value from the cache.
info/1get cache info.
keys/1return all the keys from the cache.
peek/2Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
peek/3Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
purge/1purge all items from the cache.
remove/2remove a key from the cache.
remove_oldest/1remove the oldest item from the cache.
resize/2resize of the cache.
set_size/2change the size of the cache.
size/1get the number of items in the cache.
start/1creates an LRU of the given size.
start/2creates an LRU of the given size Options are: - {evict_fun, Fun} a function that will received the evicted key value "fun(Key, Value)".
start/3creates an LRU of the given size with a registered name.
start_link/1creates an LRU of the given size as part of a supervision tree.
start_link/2creates an LRU of the given size as part of a supervision tree.
start_link/3creates an LRU of the given size as part of a supervision tree with a registered name.
stop/1stop the LRU cache.

Function Details

add/3

add(Cache::pid(), Key::term(), Value::term()) -> true | false

adds a value to the cache. Returns true if an eviction occured.

contains/2

contains(Cache::pid(), Key::term()) -> true | false

check if the key is in the cache

contains_or_add/3

contains_or_add(Cache::pid(), Key::term(), Value::term()) -> {Exists::boolean(), Evict::boolean()}

checks if a key is in the cache (without updating the recent-ness or deleting it for being stale), if not, adds the value. Returns whether found and whether an eviction occurred.

get/2

get(Cache::pid(), Key::term()) -> term() | undefined

lookup a key's value from the cache. Return undefined if it's not found.

get/3

get(Cache::pid(), Key::term(), Default::term()) -> term()

lookup a key's value from the cache. Return the Default value if it's not found.

info/1

info(Cache::pid()) -> Info::list()

get cache info

keys/1

keys(Cache::pid()) -> [term()]

return all the keys from the cache

peek/2

peek(Cache::pid(), Key::term()) -> term() | undefined

Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

peek/3

peek(Cache::pid(), Key::term(), Default::term()) -> term() | undefined

Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.

purge/1

purge(Cache::pid()) -> ok

purge all items from the cache.

remove/2

remove(Cache::pid(), Key::term()) -> ok

remove a key from the cache

remove_oldest/1

remove_oldest(Cache::pid()) -> ok

remove the oldest item from the cache

resize/2

resize(Cache::pid(), Size::non_neg_integer()) -> ok

resize of the cache

set_size/2

set_size(Cache::pid(), Size::non_neg_integer()) -> ok

change the size of the cache

size/1

size(Cache::pid()) -> non_neg_integer()

get the number of items in the cache

start/1

start(Size::non_neg_integer()) -> {ok, pid()} | {error, term()}

creates an LRU of the given size

start/2

start(Size::non_neg_integer(), Opts::[lru_option()]) -> {ok, pid()} | {error, term()}

creates an LRU of the given size Options are: - {evict_fun, Fun} a function that will received the evicted key value "fun(Key, Value)". - {spawn_opts, Opts} the spawn options. see erlang:spawn_opt/2 for more informations.

start/3

start(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()}, Size::non_neg_integer(), Opts::[lru_option()]) -> {ok, pid()} | {error, term()}

creates an LRU of the given size with a registered name

start_link/1

start_link(Size::non_neg_integer()) -> {ok, pid()} | {error, term()}

creates an LRU of the given size as part of a supervision tree

start_link/2

start_link(Size::non_neg_integer(), Opts::[lru_option()]) -> {ok, pid()} | {error, term()}

creates an LRU of the given size as part of a supervision tree

start_link/3

start_link(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()}, Size::non_neg_integer(), Opts::[lru_option()]) -> {ok, pid()} | {error, term()}

creates an LRU of the given size as part of a supervision tree with a registered name.

stop/1

stop(Cache::pid()) -> ok

stop the LRU cache


Generated by EDoc