feat(expiry): add ttl sweep process
This commit is contained in:
1 parent
c21152f0b5
commit
8683bf75fa
1 file changed
+23
@@ -0,0 +1,23 @@
|
||||
defmodule Excache.Expiry do
|
||||
@moduledoc false
|
||||
|
||||
use GenServer
|
||||
|
||||
def start_link(_arg), do: GenServer.start_link(__MODULE__, nil, name: __MODULE__)
|
||||
|
||||
@impl true
|
||||
def init(_arg) do
|
||||
interval = Application.get_env(:excache, :sweep_interval, 1000)
|
||||
schedule(interval)
|
||||
{:ok, interval}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info(:sweep, interval) do
|
||||
Excache.Store.sweep() |> Enum.each(&Excache.Notify.expired/1)
|
||||
schedule(interval)
|
||||
{:noreply, interval}
|
||||
end
|
||||
|
||||
defp schedule(interval), do: Process.send_after(self(), :sweep, interval)
|
||||
end
|
||||
Reference in new issue
Block a user