Skip to content

Commit 6d0672a

Browse files
committed
Fix the target type for the Nebulex.Event.CacheEntryEvent
1 parent 53a2516 commit 6d0672a

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

lib/nebulex/event/cache_entry_event.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ defmodule Nebulex.Event.CacheEntryEvent do
2525
@typedoc """
2626
Type for the event target.
2727
28-
The event target can be a key or a query (for `delete_all` command).
29-
If the target is a key, it will come in the shape of `{:key, deleted_key}`
30-
tuple. On the other hand, if the target is a query, it will come in the shape
31-
of a `{:query, {:in, deleted_keys}}` tuple, or a `{:query, {:q, query}}` tuple.
28+
The event can target a single key, a list of keys, or a query.
29+
30+
* A single key: `{:key, key}`. A command writing or deleting a single key
31+
will use this target. E.g., `put`, `put_new`, `replace`, `delete`, etc.
32+
* A list of keys: `{:in, [key1, key2, ...]}`. A command writing or deleting
33+
multiple keys will use this target. E.g., `put_all`, `put_new_all`, and
34+
`delete_all`.
35+
* A query: `{:q, query}`. A command deleting entries matching a query will
36+
use this target. E.g., `delete_all`.
37+
3238
"""
33-
@type target() :: {:key, any()} | {:query, {:in, [keys :: any()]} | {:q, query :: any()}}
39+
@type target() :: {:key, key :: any()} | {:in, [key :: any()]} | {:q, query :: any()}
3440

3541
@typedoc """
3642
Type for a cache entry event.

lib/nebulex/telemetry/cache_entry_handler.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ defmodule Nebulex.Telemetry.CacheEntryHandler do
106106

107107
defp do_handle(:put_all, [entries, :put_new | _], {:ok, true}, event_attrs, config) do
108108
[
109-
target: {:keys, Enum.map(entries, &elem(&1, 0))},
109+
target: {:in, Enum.map(entries, &elem(&1, 0))},
110110
command: :put_new_all
111111
]
112112
|> Kernel.++(event_attrs)
@@ -116,7 +116,7 @@ defmodule Nebulex.Telemetry.CacheEntryHandler do
116116

117117
defp do_handle(:put_all, [entries | _], {:ok, true}, event_attrs, config) do
118118
[
119-
target: {:keys, Enum.map(entries, &elem(&1, 0))},
119+
target: {:in, Enum.map(entries, &elem(&1, 0))},
120120
command: :put_all
121121
]
122122
|> Kernel.++(event_attrs)
@@ -184,7 +184,7 @@ defmodule Nebulex.Telemetry.CacheEntryHandler do
184184
)
185185
when count > 0 do
186186
[
187-
target: {:query, query},
187+
target: query,
188188
command: :delete_all
189189
]
190190
|> Kernel.++(event_attrs)

test/shared/cache/observable_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ defmodule Nebulex.Cache.ObservableTest do
6060
assert_receive ^deleted
6161

6262
entries = [foo: :bar, bar: :foo]
63-
inserted_all = %{event | target: {:keys, Keyword.keys(entries)}, command: :put_all}
63+
inserted_all = %{event | target: {:in, Keyword.keys(entries)}, command: :put_all}
6464

6565
assert cache.put_all(entries) == :ok
6666
assert_receive ^inserted_all
@@ -74,7 +74,7 @@ defmodule Nebulex.Cache.ObservableTest do
7474

7575
inserted_new_all = %{
7676
inserted_all
77-
| target: {:keys, Keyword.keys(entries)},
77+
| target: {:in, Keyword.keys(entries)},
7878
command: :put_new_all
7979
}
8080

@@ -84,7 +84,7 @@ defmodule Nebulex.Cache.ObservableTest do
8484
deleted_all = %{
8585
event
8686
| type: :deleted,
87-
target: {:query, {:in, [:foo, :bar]}},
87+
target: {:in, [:foo, :bar]},
8888
command: :delete_all
8989
}
9090

@@ -187,7 +187,7 @@ defmodule Nebulex.Cache.ObservableTest do
187187
deleted_all = %{
188188
event
189189
| type: :deleted,
190-
target: {:query, {:q, nil}},
190+
target: {:q, nil},
191191
command: :delete_all
192192
}
193193

0 commit comments

Comments
 (0)