Skip to content

Commit 8a11da8

Browse files
committed
feat: add skip_cache option for identity resolver
1 parent a63a6a0 commit 8a11da8

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ atex-*.tar
2323
/tmp/
2424

2525
.envrc
26-
.direnv
26+
.direnv
27+
.vscode/

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"git.enabled": false
3+
}

lib/atex/identity_resolver.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ defmodule Atex.IdentityResolver do
22
alias Atex.IdentityResolver.{Cache, DID, DIDDocument, Handle, Identity}
33

44
@handle_strategy Application.compile_env(:atex, :handle_resolver_strategy, :dns_first)
5+
@type options() :: {:skip_cache, boolean()}
56

67
# TODO: simplify errors
78

8-
def resolve(identifier) do
9+
@spec resolve(String.t(), list(options())) :: {:ok, Identity.t()} | {:error, any()}
10+
def resolve(identifier, opts \\ []) do
11+
opts = Keyword.validate!(opts, skip_cache: false)
12+
skip_cache = Keyword.get(opts, :skip_cache)
13+
14+
cache_result = if skip_cache, do: {:error, :not_found}, else: Cache.get(identifier)
15+
916
# If cache fetch succeeds, then the ok tuple will be retuned by the default `with` behaviour
10-
with {:error, :not_found} <- Cache.get(identifier),
17+
with {:error, :not_found} <- cache_result,
1118
{:ok, identity} <- do_resolve(identifier),
1219
identity <- Cache.insert(identity) do
1320
{:ok, identity}

lib/atex/identity_resolver/did_document.ex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ defmodule Atex.IdentityResolver.DIDDocument do
6868
@spec from_json(map()) :: {:ok, t()} | {:error, Peri.Error.t()}
6969
def from_json(%{} = map) do
7070
map
71-
# TODO: `atomize_keys` instead? Peri doesn't convert nested schemas to atoms but does for the base schema.
72-
# Smells like a PR if I've ever smelt one...
7371
|> Recase.Enumerable.convert_keys(&Recase.to_snake/1)
7472
|> schema()
7573
|> case do

0 commit comments

Comments
 (0)