View Source SuperCache.KeyValue (SuperCache v0.6.1)

Key-Value(KV) database in memory. Each KV name is store in a partition. Can use multiple KV cache by using different KV name. This is global KV cache any process can access. The KV is store in with cache. Need to start SuperCache.start!/1 before using this module. Ex:

alias SuperCache.KeyValue
SuperCache.start!()
KeyValue.add("my_kv", :key, "Hello")
KeyValue.get("my_kv", :key)
  # => "Hello"

KeyValue.remove("my_kv", :key)
KeyValue.get("my_kv", :key)
  # => nil

KeyValue.add("my_kv", :key, "Hello")
KeyValue.remove_all("my_kv")

Summary

Functions

Add key-value to cache. kv_name is used to get target partition to store data. Use can use multiple kv cache by using different kv_name. You can use any type of kv_name, key & value. Format of data is {{:kv, kv_name, key}, value} in ets table. You can use other functions of SuperCache to get data.

Count number of key-value in kv_name cache.

Get value by key. Key is belong wit kv_name.

Get all keys in kv_name cache.

Remove key-value in kv_name cache. This operaton is always success.

Remove all key-value in kv_name cache.

Convert kv_name cache to list of key-value. result has format [{key, value}]

Get all values in kv_name cache.

Functions

add(kv_name, key, value)

@spec add(any(), any(), any()) :: true

Add key-value to cache. kv_name is used to get target partition to store data. Use can use multiple kv cache by using different kv_name. You can use any type of kv_name, key & value. Format of data is {{:kv, kv_name, key}, value} in ets table. You can use other functions of SuperCache to get data.

count(kv_name)

@spec count(any()) :: integer()

Count number of key-value in kv_name cache.

get(kv_name, key, default \\ nil)

@spec get(any(), any(), any()) :: any()

Get value by key. Key is belong wit kv_name.

keys(kv_name)

@spec keys(any()) :: [any()]

Get all keys in kv_name cache.

remove(kv_name, key)

@spec remove(any(), any()) :: :ok

Remove key-value in kv_name cache. This operaton is always success.

remove_all(kv_name)

@spec remove_all(any()) :: list()

Remove all key-value in kv_name cache.

to_list(kv_name)

@spec to_list(any()) :: [{any(), any()}]

Convert kv_name cache to list of key-value. result has format [{key, value}]

values(kv_name)

@spec values(any()) :: [any()]

Get all values in kv_name cache.