add type to bucket

This commit is contained in:
Dmitry Kolesnikov 2014-06-30 21:16:07 +03:00
parent cee7ea02fc
commit 84ceff4b3a
3 changed files with 8 additions and 2 deletions

View File

@ -90,6 +90,7 @@ start() ->
%%
%% start new cache bucket, accepted options:
%% {type, set | ordered_set} - cache segment type (default set)
%% {policy, lru | mru} - cache eviction policy
%% {memory, integer()} - cache memory quota in bytes
%% {size, integer()} - cache cardinality quota

View File

@ -30,6 +30,7 @@
-define(DEF_CACHE_POLICY, lru).
%% default cache ttl and number of generations
-define(DEF_CACHE_TYPE, set).
-define(DEF_CACHE_TTL, 600).
-define(DEF_CACHE_N, 10).

View File

@ -36,7 +36,8 @@
name = undefined :: atom(), %% name of cache bucket
heap = [] :: list(), %% cache heap segments
n = ?DEF_CACHE_N :: integer(), %% number of segments
n = ?DEF_CACHE_N :: integer(), %% number of segments
type = ?DEF_CACHE_TYPE :: atom(),
ttl = ?DEF_CACHE_TTL :: integer(), %% cache time to live
policy = ?DEF_CACHE_POLICY :: integer(), %% eviction policy
@ -73,6 +74,9 @@ start_link(Name, Opts) ->
init([Name, Opts]) ->
{ok, init(Opts, #cache{name=Name})}.
init([{type, X} | T], #cache{}=S) ->
init(T, S#cache{type=X});
init([{policy, X} | T], #cache{}=S) ->
init(T, S#cache{policy=X});
@ -525,7 +529,7 @@ heap_has(_Key, []) ->
%%
%% init cache heap
init_heap(#cache{}=S) ->
Id = ets:new(undefined, [set, protected]),
Id = ets:new(undefined, [S#cache.type, protected]),
?DEBUG("cache ~p: init heap ~p~n", [S#cache.name, Id]),
Heap = #heap{
id = Id,