@@ -52,13 +52,31 @@ 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
+ 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
62
80
def get ( key , default \\ nil )
63
81
64
82
def get ( key , default ) do
@@ -71,7 +89,19 @@ defmodule Scenic.Cache do
71
89
reraise ( other , __STACKTRACE__ )
72
90
end
73
91
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
+ """
75
105
def fetch ( key )
76
106
77
107
def fetch ( key ) do
0 commit comments