-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,49 @@ | ||
defmodule Gerai do | ||
@moduledoc """ | ||
Documentation for Gerai. | ||
Client functions for caching JSON objects. | ||
## Examples | ||
iex> Gerai.get("tt1316540") | ||
"{\\\"name\\\":\\\"The Turin Horse\\\",\\\"id\\\":\\\"tt1316540\\\",\\\"genre\\\":[\\\"Drama\\\"],\\\"directed_by\\\":[\\\"Béla Tarr\\\"]}" | ||
iex> Gerai.put("tt1454468", "{\\\"name\\\":\\\"Gravity\\\",\\\"id\\\":\\\"tt1454468\\\"}") | ||
:ok | ||
iex> Gerai.get("tt1454468") | ||
{:ok, "{\\\"name\\\":\\\"Gravity\\\",\\\"id\\\":\\\"tt1454468\\\"}"} | ||
iex> Gerai.put("tt1316540", "{\\\"name\\\":\\\"The Turin Horse\\\",\\\"id\\\":\\\"tt1316540\\\"}") | ||
:ok | ||
iex> Gerai.get(:all) | ||
{:ok, | ||
["{\\\"name\\\":\\\"The Turin Horse\\\",\\\"id\\\":\\\"tt1316540\\\"}", | ||
"{\\\"name\\\":\\\"Gravity\\\",\\\"id\\\":\\\"tt1454468\\\"}"]} | ||
iex> Gerai.delete("tt1454468") | ||
:ok | ||
""" | ||
|
||
@cache_server_name GeraiJson | ||
|
||
@doc """ | ||
Get a serialised JSON from cache by ID | ||
Retrieve JSON objects from cache by ID or `:all` | ||
""" | ||
@spec get(binary) :: {:ok, binary | list[binary]} | {:error, nil} | ||
@spec get(binary | :all) :: {:ok, binary | list[binary]} | {:error, nil} | ||
def get(id), do: GenServer.call(@cache_server_name, {:get, id}) | ||
|
||
# TODO: implement as asyncronuous call `cast/handle_cast` | ||
@doc """ | ||
Cache a serialised JSON by ID | ||
""" | ||
# TODO: perhaps in asyncronuous mode with `cast/handle_cast` | ||
# handles both post and put requests | ||
@spec put(binary, binary) :: :ok | :error | ||
def put("", _), do: :error | ||
def put(nil, _), do: :error | ||
def put(id, json), do: GenServer.call(@cache_server_name, {:put, id, json}) | ||
|
||
# TODO: implement as asyncronuous call `cast/handle_cast` | ||
@doc """ | ||
Delete a JSON object from cache by ID | ||
""" | ||
# TODO: perhaps in asyncronuous mode with `cast/handle_cast` | ||
@spec delete(binary) :: :ok | :error | ||
def delete(id), do: GenServer.call(@cache_server_name, {:delete, id}) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters