From ab732202808e175eb6ae670687280b8f4dbaf1e8 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Sat, 12 Dec 2020 01:31:51 +0000 Subject: [PATCH] Define Cache.{list,clear} to help debugging Since I'm often using `iex` for interactive development, these functions are useful. --- assessments/semiprimes/server/lib/cache.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/assessments/semiprimes/server/lib/cache.ex b/assessments/semiprimes/server/lib/cache.ex index 334bf901b..cd064cc1a 100644 --- a/assessments/semiprimes/server/lib/cache.ex +++ b/assessments/semiprimes/server/lib/cache.ex @@ -24,4 +24,18 @@ defmodule Cache do def put(key, value) do Agent.update(__MODULE__, &Map.put(&1, key, value)) end + + @doc """ + List the contents of the cache. Useful for debugging purposes. + """ + def list() do + Agent.get(__MODULE__, & &1) + end + + @doc """ + Invalidate the entire cache. + """ + def clear() do + Agent.update(__MODULE__, fn _ -> %{} end) + end end