Skip to content

Commit 5ae8529

Browse files
committed
Merge branch 'cache-docs' of https://github.com/zacck/scenic into zacck-cache-docs
2 parents 818ead9 + 5f67056 commit 5ae8529

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

lib/scenic/cache.ex

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,32 @@ 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+
72+
iex> Scenic.Cache.get("test_key")
73+
nil
74+
75+
iex> :ets.insert(:scenic_cache_key_table, {"test_key", 1, :test_data})
76+
...> true
77+
...> Scenic.Cache.get("test_key")
78+
:test_data
79+
"""
80+
@spec get(term(), term()) :: term() | nil
6281
def get(key, default \\ nil)
6382

6483
def get(key, default) do
@@ -71,7 +90,19 @@ defmodule Scenic.Cache do
7190
reraise(other, __STACKTRACE__)
7291
end
7392

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

77108
def fetch(key) do

0 commit comments

Comments
 (0)