cache_name() = term()
cuckoo_cache() = #cuckoo_cache{}
fallback_fun() = fun((key()) -> {ok, value()} | {error, term()})
fingerprint_size() = 4 | 8 | 16 | 32 | 64
hash() = non_neg_integer()
hash_function() = fun((binary()) -> hash())
key() = term()
option() = {name, term()} | {ttl, timeout()} | {fingerprint_size, fingerprint_size()} | {bucket_size, pos_integer()} | {hash_function, hash_function()}
options() = [option()]
value() = term()
capacity/1 | Returns the maximum capacity of the cuckoo filter in a cache. |
delete/2 | Removes an entry from a cache. |
fetch/3 | Equivalent to fetch(Cache, Key, Fallback, Cache#cuckoo_cache.ttl). |
fetch/4 | Fetches an entry from a cache, generating a value on cache miss. |
filter_size/1 | Returns number of items in the cuckoo filter of a cache. |
get/2 | Retrieves an entry from a cache. |
new/1 | Equivalent to new(Capacity, []). |
new/2 | Creates a new cuckoo cache with the given capacity and options. |
put/3 | Equivalent to put(Cache, Key, Value, Cache#cuckoo_cache.ttl). |
put/4 | Places an entry in a cache. |
size/1 | Returns number of items in the ets table of a cache. |
whereis/1 | Retrieves a cuckoo_cache from persistent_term by its name. |
capacity(Cuckoo_cache::cuckoo_cache() | cache_name()) -> pos_integer()
Returns the maximum capacity of the cuckoo filter in a cache.
delete(Cuckoo_cache::cuckoo_cache() | cache_name(), Key::key()) -> ok | {error, not_found}
Removes an entry from a cache.
This removes the entry from both the cuckoo filter and the ets table.
Returnsok
if the deletion was successful, and returns {error, not_found}
if the element could not be found in the cuckoo filter.
fetch(Cache::cuckoo_cache() | cache_name(), Key::key(), Fallback::fallback_fun()) -> value()
Equivalent to fetch(Cache, Key, Fallback, Cache#cuckoo_cache.ttl).
fetch(Cache::cuckoo_cache() | cache_name(), Key::key(), Fallback::fallback_fun(), TTL::timeout()) -> value()
Fetches an entry from a cache, generating a value on cache miss.
If the requested entry is found in the cache, cached value is returned. If the entry is not contained in the cache, the provided fallback function will be executed and its result is returned.
If the entry does not exist in the cuckoo filter, the returned value from fallback function will not be cached in the ets table, but the key will be added to the cuckoo filter.
If the entry exists in the cuckoo filter, the returned value from fallback function will be cached in the ets table.
When a new entry is added to the cuckoo filter, if cuckoo filter does not have enough space, a random element gets removed from both the filter and the ets table.filter_size(Cuckoo_cache::cuckoo_cache() | cache_name()) -> non_neg_integer()
Returns number of items in the cuckoo filter of a cache.
get(Cuckoo_cache::cuckoo_cache() | cache_name(), Key::key()) -> {ok, value()} | {error, not_found}
Retrieves an entry from a cache.
If entry exists in the cache{ok, Value}
is returned, otherwise
{error, not_found}
is returned.
new(Capacity::pos_integer()) -> cuckoo_cache()
Equivalent to new(Capacity, []).
new(Capacity::pos_integer(), Opts::options()) -> cuckoo_cache()
Creates a new cuckoo cache with the given capacity and options.
A cuckoo cache has a built-in cuckoo filter to detect one-hit-wonders and an ets table to keep cached entries.
Given capacity is used as the capacity for the built-in cuckoo filter. Note that the actual capacity might be higher than the given capacity, because internally number of buckets in a cuckoo filter must be a power of 2.
The capacity of the ets table depends on the ratio of one-hit-wonders to the capacity of the filter, and is limited by the fingerprint key space. The size of ets table can not exceed the capacity of the cuckoo filter.
Possible options are:{name, Name}
If you give it a name, created cache instance will be stored in persistent_term, and later you can access the cache by its name.
{ttl, TTL}
Default TTL for cache entries in millisecond. If not specified,
infinity
is used. When storing an entry, TTL can be given per entry,
but if it is not, this default TTL is used.
{fingerprint_size, FingerprintSize}
This is the fingerprint size of the built-in cuckoo filter and can be one of 4, 8, 16, 32, and 64 bits. Default fingerprint size is 32 bits.
{bucket_size, BucketSize}
BucketSize of the built-in cuckoo filter must be a non negative integer, and the default value is 4. Higher bucket sizes increase false positive rate.
{hash_function, HashFunction}
You can specify a custom hash function for the built-in cuckoo filter
that accepts a binary as argument and returns hash value as an integer.
By default xxh3 hash functions are used, and you need to manually add xxh3
to the list of your project dependencies.
put(Cache::cuckoo_cache() | cache_name(), Key::key(), Value::value()) -> ok
Equivalent to put(Cache, Key, Value, Cache#cuckoo_cache.ttl).
put(Cache::cuckoo_cache() | cache_name(), Key::key(), Value::value(), TTL::timeout()) -> ok
Places an entry in a cache.
This will add the entry to both the cuckoo filter and the ets table.
If there is not enough space in the filter a random element gets removed.size(Cuckoo_cache::cuckoo_cache() | cache_name()) -> non_neg_integer()
Returns number of items in the ets table of a cache.
whereis(Name::cache_name()) -> cuckoo_cache()
Retrieves a cuckoo_cache from persistent_term by its name.
Generated by EDoc