mirror of
https://github.com/valitydev/cache.git
synced 2024-11-06 01:45:19 +00:00
add type to bucket
This commit is contained in:
parent
cee7ea02fc
commit
84ceff4b3a
@ -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
|
||||
|
@ -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).
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user