Packages

A purely Gleam Discord library built from the ground up with stratus.

Current section

Files

Jump to
glyph src glyph@internal@cache.erl
Raw

src/glyph@internal@cache.erl

-module(glyph@internal@cache).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([initialize/0, should_resume/2, resume_gateway_url/2, seq/2, session_id/2, invalid_session/2]).
-spec initialize() -> carpenter@table:set(binary(), binary()).
initialize() ->
_pipe = carpenter@table:build(<<"glyph_session"/utf8>>),
_pipe@1 = carpenter@table:privacy(_pipe, public),
_pipe@2 = carpenter@table:write_concurrency(_pipe@1, auto_write_concurrency),
_pipe@3 = carpenter@table:read_concurrency(_pipe@2, false),
_pipe@4 = carpenter@table:decentralized_counters(_pipe@3, true),
_pipe@5 = carpenter@table:compression(_pipe@4, false),
carpenter@table:set(_pipe@5).
-spec get(carpenter@table:set(binary(), binary()), binary(), binary()) -> binary().
get(Cache, Key, Default) ->
_pipe = Cache,
_pipe@1 = carpenter@table:lookup(_pipe, Key),
_pipe@2 = gleam@option:unwrap(_pipe@1, [{<<""/utf8>>, Default}]),
_pipe@3 = gleam@list:first(_pipe@2),
_pipe@4 = gleam@result:unwrap(_pipe@3, {<<""/utf8>>, Default}),
gleam@pair:second(_pipe@4).
-spec should_resume(carpenter@table:set(binary(), binary()), boolean()) -> boolean().
should_resume(Cache, Default) ->
case get(Cache, <<"should_resume"/utf8>>, <<"not found"/utf8>>) of
<<"true"/utf8>> ->
true;
<<"false"/utf8>> ->
false;
_ ->
Default
end.
-spec resume_gateway_url(carpenter@table:set(binary(), binary()), binary()) -> binary().
resume_gateway_url(Cache, Default) ->
get(Cache, <<"resume_gateway_url"/utf8>>, Default).
-spec seq(carpenter@table:set(binary(), binary()), integer()) -> integer().
seq(Cache, Default) ->
_pipe = get(Cache, <<"seq"/utf8>>, <<"not found"/utf8>>),
_pipe@1 = gleam@int:parse(_pipe),
gleam@result:unwrap(_pipe@1, Default).
-spec session_id(carpenter@table:set(binary(), binary()), binary()) -> binary().
session_id(Cache, Default) ->
get(Cache, <<"session_id"/utf8>>, Default).
-spec invalid_session(carpenter@table:set(binary(), binary()), boolean()) -> boolean().
invalid_session(Cache, Default) ->
case get(Cache, <<"invalid_session"/utf8>>, <<"not found"/utf8>>) of
<<"true"/utf8>> ->
true;
<<"false"/utf8>> ->
false;
_ ->
Default
end.