@@ -52,13 +52,32 @@ defmodule Scenic.Cache do
52
52
53
53
# ===========================================================================
54
54
defmodule Error do
55
+ @ moduledoc """
56
+ Defines the exception thrown by the CacheModule
57
+ """
55
58
defexception message: nil
56
59
end
57
60
58
- # ============================================================================
59
61
# client apis
60
62
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
62
81
def get ( key , default \\ nil )
63
82
64
83
def get ( key , default ) do
@@ -71,7 +90,19 @@ defmodule Scenic.Cache do
71
90
reraise ( other , __STACKTRACE__ )
72
91
end
73
92
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
+ """
75
106
def fetch ( key )
76
107
77
108
def fetch ( key ) do
0 commit comments