Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ETScache

ETScache is very(!) simple, self-contained memory cache, using only ETS tables in Erlang. You can create a cache with a maximum number of elements in it, and when this limit is exceed, the oldest element is eliminated.

It has the following functions

  • new (max_size) -> etscache
  • put_new (etscache, key, value) -> ok ; {error, "Already exists!"}
  • update (etscache, key, value) -> ok
  • get (etscache, key) -> value

It is design to perform rapidly: Get is constant O(1); Put_New is constant O(1); Update is linear with the number os elements in cache O(N).

Author

Ricardo Gonçalves tome.wave@gmail.com

How To Use

	% Create a new cache
    C = etscache:new(128),      %start takes 1 argument, the maximum number of elememts in cache

	% Add a key/value
	ok = etscache:put_new(C, key1, "v1"), 
	
	% put_new only adds new values
	{error,_} = etscache:put_new(C, key1, "cenas"), 
	
	% Update an existing value
	etscache:update(C, key1, "v11"), 
	
	% Get the value for some key
    case etscache:get(C, key1) of
      not_found -> io:format("Value not Found!~n");
      {ok, Value} -> io:format("Value found -> ~p~n", [Value])
    end.

Test It

Function test gives and example of a possible run, and output the cache in the end, to check its state.

~$ cd "ETScacheFolder"
~$ erlc etscache.erl 
~$ erl -noshell -s etscache test -s init stop

TODO

About

A simple erlang in-memory cache

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages