View Source SuperCache (SuperCache v0.5.2)

SeperCache is a library support for caching data in memory. The library is based on Ets table. SuperCache support auto scale based on number of cpu cores and easy to use. type of data is supported is tuple, other type of data can put in a tuple an storage in SuperCache.

Note: This version doesn't support for cluster.

Link to this section Summary

Functions

Detele data in cache with key & partition store same as put! function

Detele all data in cache.

Delete data in a partition by key & data which used to get partition.

Same as delete_by_match but with all partitions in cache.

Delete data by pattern in a partition.

Delete data in a partition by key & data which used to get partition is key.

Same with get!/1 function but doesn's raise error if failed.

Get data (list of tuple) from cache. This is simple way to get data but need key & partition data must same postion with config.

Get data from cache with key and paritition. Function return list of tuple.

Scan all storage partitions with pattern.

Gets objects in storage by pattern matching. If partition data is atom :_, it will scan all partitions.

Function works like get_by_match_object!/2, it will scan all partitions.

The function works like :ets.match_object/2. partitiondata is used to get partition. if partition_data = : the function will scan all partitions.

Get data from cache in case key_pos & partition in config is same. Function return list of tuple.

Data is push to buffer before it was written to cache. If you don't need read data immediately this will help improve performance.

Store tuple to cache. The function works like put!(data) Result return is true or {:error, reason}

Store tuple to cache.

Function works like scan!/2 but with all paritions.

Function is used to call anonymous function with data(tuple) in a partition. acc parameter is used to call function with special options or store data.

Init & start library.

Start library with config. Parameters like start!(opts)

Start SuperCache service. This function will use default config.

Start SuperCache service with config.

Check library is started or not.

Get stats in all tables

Clear data & stop library. Call if application no more use SuperCache to free memory.

Link to this section Functions

@spec delete!(tuple()) :: :ok

Detele data in cache with key & partition store same as put! function

@spec delete_all() :: :ok

Detele all data in cache.

Link to this function

delete_by_key_partition!(key, partition_data)

View Source
@spec delete_by_key_partition!(any(), any()) :: true

Delete data in a partition by key & data which used to get partition.

Link to this function

delete_by_match!(pattern)

View Source
@spec delete_by_match!(tuple()) :: any()

Same as delete_by_match but with all partitions in cache.

Link to this function

delete_by_match!(partition_data, pattern)

View Source
@spec delete_by_match!(any(), tuple()) :: any()

Delete data by pattern in a partition.

Link to this function

delete_same_key_partition!(key)

View Source
@spec delete_same_key_partition!(any()) :: true

Delete data in a partition by key & data which used to get partition is key.

@spec get(tuple()) ::
  [tuple()]
  | {:error,
     %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}}

Same with get!/1 function but doesn's raise error if failed.

@spec get!(tuple()) :: [tuple()]

Get data (list of tuple) from cache. This is simple way to get data but need key & partition data must same postion with config.

Link to this function

get_by_key_partition!(key, partition)

View Source
@spec get_by_key_partition!(any(), any()) :: [tuple()]

Get data from cache with key and paritition. Function return list of tuple.

@spec get_by_match!(tuple()) :: any()

Scan all storage partitions with pattern.

Function works like :ets.

Link to this function

get_by_match!(partition_data, pattern)

View Source
@spec get_by_match!(any(), tuple()) :: any()

Gets objects in storage by pattern matching. If partition data is atom :_, it will scan all partitions.

Function works like :ets.match_pattern/2

Link to this function

get_by_match_object!(pattern)

View Source
@spec get_by_match_object!(tuple()) :: any()

Function works like get_by_match_object!/2, it will scan all partitions.

Link to this function

get_by_match_object!(partition_data, pattern)

View Source
@spec get_by_match_object!(any(), tuple()) :: any()

The function works like :ets.match_object/2. partitiondata is used to get partition. if partition_data = : the function will scan all partitions.

Link to this function

get_same_key_partition!(key)

View Source
@spec get_same_key_partition!(any()) :: [tuple()]

Get data from cache in case key_pos & partition in config is same. Function return list of tuple.

@spec lazy_put(tuple()) :: any()

Data is push to buffer before it was written to cache. If you don't need read data immediately this will help improve performance.

@spec put(tuple()) ::
  true
  | {:error,
     %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}}

Store tuple to cache. The function works like put!(data) Result return is true or {:error, reason}

@spec put!(tuple()) :: true

Store tuple to cache.

Tuple size of parameter must be equal or larger than key_pos/partition_pos.

The function must call after start! SuperCache.

If success the function will return true, other cases it will raise a error.

@spec scan!((any(), any() -> any()), any()) :: any()

Function works like scan!/2 but with all paritions.

Link to this function

scan!(partition_data, fun, acc)

View Source
@spec scan!(any(), (any(), any() -> any()), any()) :: any()

Function is used to call anonymous function with data(tuple) in a partition. acc parameter is used to call function with special options or store data.

@spec start() ::
  :ok
  | {:error,
     %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}}

Init & start library.

Function uses default config like start!()

@spec start(any()) ::
  :ok
  | {:error,
     %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}}

Start library with config. Parameters like start!(opts)

@spec start!() :: :ok

Start SuperCache service. This function will use default config.

If function is failed, it will raise a error.

Default config:

  • key_pos: 0
  • partition_pos: 0
  • table_type: :set
  • num_partition: = number of online_schedulers of Erlang VM
@spec start!([tuple()]) :: :ok

Start SuperCache service with config.

Config is in Keyword list

If key_pos or parition_pos is missed, start SuperCache will fail.

@spec started?() :: boolean()

Check library is started or not.

Get stats in all tables

@spec stop() :: :ok

Clear data & stop library. Call if application no more use SuperCache to free memory.