View Source SuperCache (SuperCache v0.6.1)

SeperCache is a library support for caching data in memory. The library is based on Ets table and use some function from :ets for making it easy & friendly to use. 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. Current version is not support for replicating data to multi nodes in Elixir cluster.

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 (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.

Functions

delete!(data)

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

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

delete_all()

@spec delete_all() :: :ok

Detele all data in cache.

delete_by_key_partition!(key, partition_data)

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

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

delete_by_match!(pattern)

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

Same as delete_by_match but with all partitions in cache.

delete_by_match!(partition_data, pattern)

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

Delete data by pattern in a partition.

delete_same_key_partition!(key)

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

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

get(data)

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

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

get!(data)

@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.

get_by_key_partition!(key, partition)

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

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

get_by_match!(pattern)

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

Scan all storage partitions with pattern.

Function works like :ets.

get_by_match!(partition_data, pattern)

@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

get_by_match_object!(pattern)

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

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

get_by_match_object!(partition_data, pattern)

@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.

get_same_key_partition!(key)

@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.

lazy_put(data)

@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.

put(data)

@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}

put!(data)

@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.

scan!(fun, acc)

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

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

scan!(partition_data, fun, acc)

@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.

start()

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

Init & start library.

Function uses default config like start!()

start(opts)

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

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

start!()

@spec start!() :: :ok

Start SuperCache service (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

start!(opts)

@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 raise an error.

started?()

@spec started?() :: boolean()

Check library is started or not.

stats()

Get stats in all tables

stop()

@spec stop() :: :ok

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