Skip to content

Commit a14816e

Browse files
committed
Merge branch 'zacck-cache-docs'
2 parents 818ead9 + cad4fbe commit a14816e

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lib/scenic/cache.ex

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,31 @@ defmodule Scenic.Cache do
5252

5353
# ===========================================================================
5454
defmodule Error do
55+
@moduledoc """
56+
Defines the exception thrown by the CacheModule
57+
"""
5558
defexception message: nil
5659
end
5760

58-
# ============================================================================
5961
# client apis
6062

61-
# --------------------------------------------------------
63+
@doc """
64+
This function to collects an item from the Cache.
65+
This function accepts a key and a default both being any term in Elixir.
66+
67+
If there is no item in the Cache that corresponds to the key the function will return nil else the
68+
function returns the term stored in the cache with the using the provided key
69+
70+
## Examples
71+
iex> Scenic.Cache.get("test_key")
72+
nil
73+
74+
iex> :ets.insert(:scenic_cache_key_table, {"test_key", 1, :test_data})
75+
...> true
76+
...> Scenic.Cache.get("test_key")
77+
:test_data
78+
"""
79+
@spec get(term(), term()) :: term() | nil
6280
def get(key, default \\ nil)
6381

6482
def get(key, default) do
@@ -71,7 +89,19 @@ defmodule Scenic.Cache do
7189
reraise(other, __STACKTRACE__)
7290
end
7391

74-
# --------------------------------------------------------
92+
@doc """
93+
This function works the same as the `get` function. That is it accepts a key paramter and returns a ok/error tuple i
94+
making this function ideal if you need to pattern match on the result of getting from the cache
95+
96+
## Examples
97+
iex> Scenic.Cache.fetch("test_key")
98+
{:error, :not_found}
99+
100+
iex> :ets.insert(:scenic_cache_key_table, {"test_key", 1, :test_data})
101+
...> true
102+
...> Scenic.Cache.fetch("test_key")
103+
{:ok, :test_data}
104+
"""
75105
def fetch(key)
76106

77107
def fetch(key) do

0 commit comments

Comments
 (0)